I have Gridview. In the Gridview I have a TemplateField that has an EditItemTemplate with a Textbox in it. The Gridview also has a CommandField with ShowEditButton set to true.
As you might expect from this brief description, when the user hits the Edit button on a row, the row goes into an edit mode and the Textbox shows up and the user is able to edit the value.
Here is my question. How can I set the properties of the Textbox? For example, depending on certain conditions, I want to disable the Textbox so that the user can not edit the existing value. I think the first thing I need to know is what is the Event on
the Gridview that I need to write the code in?
Maybe someone will be better than me on finding a specific example.
How can I set the properties of the Textbox? For example, depending on certain conditions, I want to disable the Textbox so that the user can not edit the existing value. I think the first thing I need to know is what is the Event on the Gridview that I need
to write the code in?
You can use the Gridview rowediting event and then find the row which is in editmode. From the row you can find the textbox control and disable it
/// <summary>
/// Handles the RowEditing event of the GridView1 control.
/// </summary>
/// <param name="sender">The source of the event.</param>
/// <param name="e">The <see cref="System.Web.UI.WebControls.GridViewEditEventArgs"/> instance containing the event data.</param>
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
//Set the edit index in gridview
GridView1.EditIndex = e.NewEditIndex;
//calling the method to bind grid with data again
GetCustomerDetails();
//Provide your condition here
if("your condition is true")
{
//Here you can find the textbox control which you want to disable
//change textbox id here
TextBox txtbox = (TextBox)GridView1.Rows[e.NewEditIndex].FindControl("TextBox1");
txtbox.Enabled=false;
}
}
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
17 Points
65 Posts
set the properties of a Textbox in an EditItemTemplate
Feb 23, 2017 05:03 PM|NewKid1nTown|LINK
I have Gridview. In the Gridview I have a TemplateField that has an EditItemTemplate with a Textbox in it. The Gridview also has a CommandField with ShowEditButton set to true.
As you might expect from this brief description, when the user hits the Edit button on a row, the row goes into an edit mode and the Textbox shows up and the user is able to edit the value.
Here is my question. How can I set the properties of the Textbox? For example, depending on certain conditions, I want to disable the Textbox so that the user can not edit the existing value. I think the first thing I need to know is what is the Event on the Gridview that I need to write the code in?
Maybe someone will be better than me on finding a specific example.
All-Star
50831 Points
9895 Posts
Re: set the properties of a Textbox in an EditItemTemplate
Feb 23, 2017 06:08 PM|A2H|LINK
You can use the Gridview rowediting event and then find the row which is in editmode. From the row you can find the textbox control and disable it
Source URL
Aje
My Blog | Dotnet Funda
Contributor
6730 Points
2715 Posts
Re: set the properties of a Textbox in an EditItemTemplate
Feb 24, 2017 08:42 AM|Eric Du|LINK
Hi NewKid1nTown,
According to your description, I make a sample, I think you could add condition to judge, then disable the control. Here is the complete sample code:
I judge the textbox1 value, if textbox1 value equal to "234", then disable textbox2, this will disable edit of textbox2.
Sample Code:
Result:
Best Regards,
Eric Du
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.