|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
How to read Column0 from DataGridPlease show sample as I am new to this stuff. Help is greatly appreciated. ** DataGrid ** Column0 Column1 Edit Del John John Sample ** end ** void DataGrid_Edit(object sender, DataGridCommandEventArgs e) { if (!isEditing) { DataGrid1.EditItemIndex = e.Item.ItemIndex; Response.BufferOutput = true; // working int keyValue = e.Item.ItemIndex; //eg 3 string strline = "http://localhost/Quote/Employee/AddUser.aspx?id="+keyValue; Response.Redirect(strline,true); } } void BindGrid() { SqlConnection dbConnection = new SqlConnection(ConnectionString); SqlCommand dbCommand = new SqlCommand(); dbCommand.CommandText = SelectCommand; dbCommand.Connection = dbConnection; SqlDataReader dr; dbConnection.Open(); dr = dbCommand.ExecuteReader(); DataTable dt = new DataTable(); dt.Columns.Add("User ID"); dt.Columns.Add("Username"); dt.Columns.Add("Email"); dt.Columns.Add("Create Date"); dt.Columns.Add("Terminate Date"); while (dr.Read()) { DataRow r; r = dt.NewRow(); r[0] = dr["Uid"].ToString().Trim(); r[1] = dr["Username"].ToString().Trim(); r[2] = dr["Email"].ToString().Trim(); DateTime dtcdate = Convert.ToDateTime(dr["CreateDate"]); r[3] = string.Format("{0:d}",dtcdate); DateTime dttdate = Convert.ToDateTime(dr["TerminateDate"]); r[4] = string.Format("{0:d}",dttdate); dt.Rows.Add(r); } DataGrid1.DataSource = dt; DataGrid1.DataBind(); } -------------------------------- From: brian yeo ----------------------- Posted by a user from .NET 247 (http://www.dotnet247.com/) <Id>dCycS+rsUUCknB6jgO8uOw==</Id> Hi Brian,
If it's a BoundColumn, you can use e.Item.Cells[colIndex].Text to get value in the colIndex. For your case you may use string strUid = e.Item.Cells[2].Text; HTH Elton Wang elton_w***@hotmail.com >-----Original Message----- illustrated below, I was able to retrieve the ItemIndex >I could not get the User ID/Column0 from the datagrid. As when I click the Edit button. What is the best method to get the User ID/Column0 (primary key) from the ItemIndex and pass the User ID to KeyValue? DataKeyField is not used due to date formatting reason. Show quoteHide quote > = "http://localhost/Quote/Employee/AddUser.aspx?>Please show sample as I am new to this stuff. Help is greatly appreciated. > >** DataGrid ** > Column0 Column1 >Edit Del John John Sample > >** end ** > >void DataGrid_Edit(object sender, DataGridCommandEventArgs e) { > > if (!isEditing) { > DataGrid1.EditItemIndex = e.Item.ItemIndex; > Response.BufferOutput = true; > > // working > int keyValue = e.Item.ItemIndex; //eg 3 > > string strline id="+keyValue; Show quoteHide quote > Response.Redirect(strline,true); > } >} > > >void BindGrid() { > SqlConnection dbConnection = new SqlConnection (ConnectionString); > SqlCommand dbCommand = new SqlCommand(); > > dbCommand.CommandText = SelectCommand; > dbCommand.Connection = dbConnection; > > SqlDataReader dr; > dbConnection.Open(); > dr = dbCommand.ExecuteReader(); > > DataTable dt = new DataTable(); > dt.Columns.Add("User ID"); > dt.Columns.Add("Username"); > dt.Columns.Add("Email"); > dt.Columns.Add("Create Date"); > dt.Columns.Add("Terminate Date"); > > while (dr.Read()) > { > DataRow r; > > r = dt.NewRow(); > > r[0] = dr["Uid"].ToString().Trim(); > r[1] = dr["Username"].ToString().Trim(); > r[2] = dr["Email"].ToString().Trim(); > DateTime dtcdate = Convert.ToDateTime(dr ["CreateDate"]); > r[3] = string.Format("{0:d}",dtcdate); > > DateTime dttdate = Convert.ToDateTime(dr ["TerminateDate"]); > r[4] = string.Format("{0:d}",dttdate); > > dt.Rows.Add(r); > } > > DataGrid1.DataSource = dt; > DataGrid1.DataBind(); > >} > >-------------------------------- >From: brian yeo > >----------------------- >Posted by a user from .NET 247 (http://www.dotnet247.com/) > ><Id>dCycS+rsUUCknB6jgO8uOw==</Id> >. >
Newbie Question on Web DataGrid Focus
Avoid adding a new record on refreshing the browser 2 Performance Questions Underline a whole row for a particular row CancelCommand Event Handler Not Firing Embedded DropDownList in column. Help needed with DataGrid Client-Side Scripting Row Span in a grid? Access a BoundColumn's value in Update, other than .Cells()? DataGrid & Form on Same Page Post Issue |
|||||||||||||||||||||||