Get TextBox ID

  • Thread starter Thread starter rn5a
  • Start date Start date
R

rn5a

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?
 
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

... See
http://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
 
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

Mark, I am using a DataGrid & NOT a GridView & DataGrid doesn't have
any event named RowCommand! So I can't use the RowCommand event.

Any other ideas/suggestions using a DataGrid?
 
Hello rn5,

If you're using a DataGrid control, you probably want to handle either the
ItemEdit command or the UpdateCommand, depending on what you're exactly
doing. My guess is that you want to handle the update and are looking for
user input. For either case you want to look in the e.Item.Cells collection
for the controls. If you're developing for version 2 of the .NET Framework,
you might want to take a look at the GridView control.
=-=-=-
void ItemsGrid_Update(Object sender, DataGridCommandEventArgs e)
{

// Retrieve the text boxes that contain the values to update.
// For bound columns, the edited value is stored in a TextBox.
// The TextBox is the 0th control in a cell's Controls collection.
// Each cell in the Cells collection of a DataGrid item represents
// a column in the DataGrid control.
TextBox qtyText = (TextBox)e.Item.Cells[3].Controls[0];
TextBox priceText = (TextBox)e.Item.Cells[4].Controls[0];

// Retrieve the updated values.
String item = e.Item.Cells[2].Text;
....... // more processing

--
brians
http://www.limbertech.com


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

Mark, I am using a DataGrid & NOT a GridView & DataGrid doesn't have
any event named RowCommand! So I can't use the RowCommand event.

Any other ideas/suggestions using a DataGrid?
 
Back
Top