Showing posts with label Gridview. Show all posts
Showing posts with label Gridview. Show all posts

Monday, May 24, 2010

IMPORTING EXCEL FILE INTO ASP.NET GRIDVIEW

protected void Button1_Click(object sender, EventArgs e)
{
string xConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + Server.MapPath("ExcelImport.xls") + ";" +
"Extended Properties=Excel 8.0;";

OleDbConnection objXConn = new OleDbConnection(xConnStr);
string sql = "SELECT * FROM [Salary$]";
OleDbCommand cmd = objXConn.CreateCommand();
cmd.CommandText = sql;
OleDbDataAdapter adpt = new OleDbDataAdapter();
adpt.SelectCommand = cmd;
DataSet ds = new DataSet();
adpt.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();


}

Wednesday, May 21, 2008

How to add a textbox inside a gridview

First add a gridview in your page and go to the source view of your page and find the gridview inside which you want to add the textbox and you can insert a code as below (the one in bold blue color) and it will add the textbox into the gridview when it is bound to the database object.

-------------------------------------------------------------
Just below it is the code with which you can access these individual textbox in the different rows.
-------------------------------------------------------------------------------------
for (int j = 0; j < GridView1.Rows.Count; j++)
{
Control cnt;
cnt = GridView1.Rows[j].Cells[3].Controls[1];
cnt = GridView1.Rows[j].FindControl("txtValue");
TextBox txtBx = (TextBox)cnt;
//write your code here to maniupulate the content of textbox



}