A DataGrid has a BoundColumn, an EditCommandColumn & a few
TemplateColumns. When the text in the EditCommandColumn within any of
the DataGridItems is clicked, the corresponding BoundColumn changes to
a TextBox.
How do I get the ID of such a TextBox?
You need to set the onRowCommand and retrieve the cell by its offset in the
row that is clicked
.. Seehttp://
www.thescripts.com/forum/thread454303.html
This is code from one of my gridviews
-snip---aspx---------
onRowCommand="spreadEditOnRowCommand"
DataSourceID="SqlDataSource6"
ForeColor="Black"
GridLines="Vertical"
Style="z-index: 101; left: 0px; position: absolute; top: 250px">
<FooterStyle BackColor="#CCCC99" />
<Columns>
<asp:ButtonField ButtonType="Button" CommandName="Details" Text="Sync" />
<asp:BoundField DataField="umeno" HeaderText="umeno" ReadOnly="True"
SortExpression="umeno" />
<asp:BoundField DataField="articleno" HeaderText="articleno"
ReadOnly="True" SortExpression="articleno" />
<asp:BoundField DataField="spreadno" HeaderText="spreadno"
ReadOnly="True" SortExpression="spreadno" />
<asp:BoundField DataField="description" HeaderText="description"
SortExpression="description" />
<asp:BoundField DataField="spreadimage" HeaderText="spreadimage"
SortExpression="spreadimage" />
</Columns>
-snap----aspx.cs--------
protected void spreadEditOnRowCommand(object src, GridViewCommandEventArgs
e)
{
if (e.CommandName == "Details")
{
// get the row index stored in the CommandArgument property
int index = Convert.ToInt32(e.CommandArgument);
// get the GridViewRow where the command is raised
GridViewRow selectedRow = ((GridView)e.CommandSource).Rows[index];
// get the spreadno
string spreadSpreadNo = selectedRow.Cells[3].Text;
// Store the spreadno
Session["spreadno"] = spreadSpreadNo;
}
}
--snop-----------
Mark