Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP ASP.NET .NET C#4.0 .NET4 , +
Hi all,
So here is the situation. I have a Gridview with a field containing textbox. I have hidden the field and made the textbox disabled, that is Enabled = False. There is another field in the Gridview containing LinkButton. On clicking on a linkbutton of any row, i want to make the column with textbox visible and enable only the textbox of the row from which the linkbutton was clicked. I used the below code. It is showing the textbox column, but all the textbox are disabled. Please help.
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "due_payment")
        {
            GridView1.Columns[8].Visible = true;
 
            int rowIndex = Convert.ToInt32(e.CommandArgument);
            TextBox txt =(TextBox)GridView1.Rows[rowIndex].FindControl("TextBox4");
            txt.Enabled = true;
        }
    }
 
Thanks..
Posted 24-Nov-12 7:45am
Edited 24-Nov-12 7:46am
v2
Comments
Tadit Dash at 24-Nov-12 14:10pm
   
Have you checked that the rowindex you are getting is correct or not ?
Please check with debugger that whether you are getting the rowindex of the row, from which the link button is clicked ?
Aritra Nath at 25-Nov-12 1:09am
   
Yes i am getting the rowindex correct. Also the textbox is being detected correctly. But it is not getting enabled.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

I think you must get the Id of selected row in grid view and then using Id of that row you can enable your text box.I hope you are getting Command argument by this type in GridView
 
CommandArgument='<%# DataBinder.Eval(Container, "RowIndex") %>'
 
if not apply it.
 
Also check again your textbox Id it must be same in the grid view.
 

}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Check This. I don't know what is your HTML code is, so i posted this working example as your requiremnts.
You Just have to bind the Gridview. and it will work as your requirement
the Gridview Code.
 
<asp:GridView ID="GridView1" runat="server" GridLines="None"
         EmptyDataText="No Rcords Found" AutoGenerateColumns="False"
         onrowcommand="GridView1_RowCommand" onrowdatabound="GridView1_RowDataBound">
         <Columns>
             <asp:TemplateField>
                 <EditItemTemplate>
                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                 </EditItemTemplate>
                 <ItemTemplate>
                     <asp:LinkButton CommandArgument='<%# ((GridViewRow) Container).RowIndex %>' ID="LinkButton1" runat="server" CommandName="sel">Select</asp:LinkButton>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="ID">
                 <EditItemTemplate>
                 </EditItemTemplate>
                 <ItemTemplate>
                     <asp:TextBox ID="TextBox2" runat="server" Text='<%#Eval("ID") %>' Enabled="false"></asp:TextBox>
                 </ItemTemplate>
             </asp:TemplateField>
             <asp:TemplateField HeaderText="name" Visible="false">
                 <EditItemTemplate>
                     <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                 </EditItemTemplate>
                 <ItemTemplate>
                     <asp:TextBox ID="TextBox1" runat="server" Text='<%#Eval("name") %>' Enabled="false"></asp:TextBox>
                 </ItemTemplate>
             </asp:TemplateField>
         </Columns>
 
         
 
and on row command
 
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "sel")
       {
           int rowIndex = Convert.ToInt32(e.CommandArgument);
           GridView1.Columns[2].Visible = true;
           TextBox txt = (TextBox)GridView1.Rows[rowIndex].FindControl("TextBox1");
           txt.Enabled = true;
       }
   }
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 539
1 Maciej Los 300
2 DamithSL 233
3 Sergey Alexandrovich Kryukov 209
4 BillWoodruff 200
0 OriginalGriff 7,168
1 Sergey Alexandrovich Kryukov 6,377
2 DamithSL 5,461
3 Manas Bhardwaj 4,876
4 Maciej Los 4,450


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100