Getting a reference to a control on GridView RowEditing event
-
hi i'm trying to get a reference to a control on GridView RowEditing event: code behind:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{TextBox txtEditMsg = (TextBox)gvChores.Rows[e.NewEditIndex].FindControl("txtEditMsg");}javascript:
<asp:TemplateField HeaderText="Chore">
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtEditMsg" Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
</EditItemTemplate>
</asp:TemplateField>i can't get the reference (returns null) can anyone advice what i'm doing wrong and how can i get the reference to the control? thanks in advance
-
hi i'm trying to get a reference to a control on GridView RowEditing event: code behind:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{TextBox txtEditMsg = (TextBox)gvChores.Rows[e.NewEditIndex].FindControl("txtEditMsg");}javascript:
<asp:TemplateField HeaderText="Chore">
<EditItemTemplate>
<asp:TextBox runat="server" ID="txtEditMsg" Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
</EditItemTemplate>
</asp:TemplateField>i can't get the reference (returns null) can anyone advice what i'm doing wrong and how can i get the reference to the control? thanks in advance
try:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{
TextBox txtEditMsg = (TextBox)e.Item.FindControl("txtEditMsg");
}remember that the DataRowView is:
System.Data.DataRowView drv = (System.Data.DataRowView)e.Item.DataItem;
Hope it helps Thomas
-
try:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{
TextBox txtEditMsg = (TextBox)e.Item.FindControl("txtEditMsg");
}remember that the DataRowView is:
System.Data.DataRowView drv = (System.Data.DataRowView)e.Item.DataItem;
Hope it helps Thomas
-
Sorry, I was thinking about DataGrid not a GridView. It seems to me that you are trying to uppdate the row, hens the
Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
So you should use:
protected void gvChores_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvChores.Rows[e.RowIndex];
TextBox txtEditMsg = (TextBox)row.FindControl("txtEditMsg");
}Becouse RowEditing works like this:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
gvChores.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
BindData();
}To be honest, I have never used GridView since I always use DataGrid, so I might be wrong.
modified on Thursday, October 2, 2008 6:09 AM
-
Sorry, I was thinking about DataGrid not a GridView. It seems to me that you are trying to uppdate the row, hens the
Text='<%# DataBinder.Eval(Container.DataItem,"Chore_contents") %>'/>
So you should use:
protected void gvChores_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = gvChores.Rows[e.RowIndex];
TextBox txtEditMsg = (TextBox)row.FindControl("txtEditMsg");
}Becouse RowEditing works like this:
protected void gvChores_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index.
gvChores.EditIndex = e.NewEditIndex;
//Bind data to the GridView control.
BindData();
}To be honest, I have never used GridView since I always use DataGrid, so I might be wrong.
modified on Thursday, October 2, 2008 6:09 AM