Editable GridView
-
Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:
<asp:TemplateField HeaderText="החל מ-">
<EditItemTemplate>
<asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event -
TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart");
but i got "Object reference not set to an instance of an object". Can some one please help me with this problem? -
Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:
<asp:TemplateField HeaderText="החל מ-">
<EditItemTemplate>
<asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event -
TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart");
but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?Have you debugged it? I would more than likely handle this on the client-side with some JavaScript.
I know the language. I've read a book. - _Madmatt
-
Have you debugged it? I would more than likely handle this on the client-side with some JavaScript.
I know the language. I've read a book. - _Madmatt
-
Mark Nischalke wrote:
I would more than likely handle this on the client-side with some JavaScript.
What you suggest to do? I never did javascript on grid... :(
treuveni wrote:
What you suggest to do?
learn JavaScript.
I know the language. I've read a book. - _Madmatt
-
treuveni wrote:
What you suggest to do?
learn JavaScript.
I know the language. I've read a book. - _Madmatt
-
Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:
<asp:TemplateField HeaderText="החל מ-">
<EditItemTemplate>
<asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event -
TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart");
but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?You might try doing this in RowDataBound event:
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (GridViewIpTab.EditIndex == e.Row.RowIndex)
{
TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.Row.RowIndex].FindControl("txtStart");
// Do what you need to do
}
}In RowEditing do:
GridViewIpTab.EditIndex = e.NewEditIndex; BindYourGrid();
- S 50 cups of coffee and you know it's on! Code, follow, or get out of the way.
-
Hi, I have a gridview with Edit And Delete buttons. Here is one of the columns:
<asp:TemplateField HeaderText="החל מ-">
<EditItemTemplate>
<asp:TextBox ID="txtStart" Width="150px" ReadOnly="true" BackColor="LightSteelBlue" runat="server" Text='<%# Bind("startHour") %>'></asp:TextBox></EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtStartNew" Width="150px" runat="server"></asp:TextBox></FooterTemplate>
<ItemTemplate>
<asp:Label ID="lblMStart" Width="150px" runat="server" Text='<%# Bind("startHour") %>'></asp:Label></ItemTemplate>
</asp:TemplateField>I've set the TextBox in the EditItemTemplate to ReadOnly. My Problem is- that i want to change the property (ReadOnly) to False after i pressed on the Edit button if some cell has a value. I've tried to do this in the RowEditing event -
TextBox txtStart = (TextBox)GridViewIpTab.Rows[e.RowIndex].FindControl("txtStart");
but i got "Object reference not set to an instance of an object". Can some one please help me with this problem?You can reference this example: protected void gv4PPdata_RowDataBound(object sender, GridViewRowEventArgs e) { if((e.Row.RowState & DataControlRowState.Edit) > 0) { TextBox curText; for (int i = 1; i <= 6; i++) { curText = (TextBox)e.Row.Cells[i].Controls[0]; curText.Width = Unit.Pixel(60); if (i == 1) { curText.Enabled = false; } } } } Reference: http://www.programlive.tk