Click here to Skip to main content
15,883,883 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
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.

C#
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
Updated 8-May-18 7:41am
v2
Comments
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 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.

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.


}
 
Share this answer
 
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.

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

C#
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;
       }
   }
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900