tags:

views:

222

answers:

1

i have an gridview control with a comment text, link button, and an

invisible (text box and a button to post to database.)

when i click on the link button i want to show the textbox.

can any one help me how to do this.

my gridview code:

enter code here <asp:GridView ID="grdComments" runat="server" AutoGenerateColumns="False">
<Columns>
    <asp:TemplateField>
        <ItemTemplate>
            <table width="500px" cellpadding="3" cellspacing="3">
                <tr/>
                    <td/>
                        <asp:Label runat="server" ID="lblLeftPad"></asp:Label>
                        <asp:Label runat="server" ID="lblComment" Text='<%# container.dataitem("CommentText") %>'></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        <asp:LinkButton ID="lbtnReply" Text="Reply" runat="server" CommandName="CommentReply"></asp:LinkButton>
                    </td>
                </tr>
                <tr>
                        <td>
                            </asp:TextBox ID="txtReply" runat="server" Height="50px" Width="500px" Visible="false"></asp:TextBox>
                        </td>
                    </tr>
               </table>

        </ItemTemplate>
    </asp:TemplateField>
</Columns>

+1  A: 

If you are not using Javascript / AJAX then on the link button's click event set the textbox's visible value to true. The link button automatically sends a postback so this would work unless you have the link button set to not auto postback.

EDIT: To access link button

There are a few ways depending on how you setup your grid. If this is a Command Field or a button field that you are using then you can use the RowCommand and the e.CommandArgument to now which row you are on and then set the textbox to true. Below is a sample:

    row = Integer.Parse(e.CommandArgument)
    GridView1.Rows(row).Cells(1).Controls(1).Visible = True

The cell is set to the column you are wanting to work on and the controls # is set to the control you want to work with in the cell. There is more than one control created in a cell even if you only put a textbox. You can use the FindControl syntax to more reliably get at your control.

If you created a templated field with the link button then on the command argument for the link button set it's value to: =<%# CType(Container,GridViewRow).RowIndex %>

and the above code in the gridview's rowcommand will work.

OR you can set the link buttons click event to something like:

gridview1.rows(directcast(sender,LinkButton).CommandArgument).cells(1).Controls(1).visible = true

You can get to the link buttons click event in a templated field by editing the template from the GUI and double clicking on the link button.

I would recommend using the RowCommand option and using the FindControl Syntax to make your app more readable and easier to maintain.

klabranche
Link button control is not available in the aspx.vb page as it is inside the grid view.
vamsivanka
You can still get at the link buttons click event. See my edit to explain in more detail the options you have. :)
klabranche
Yep it working. Thanks klabranche..
vamsivanka
Great to be of help!
klabranche
Could you up vote me and select it as the correct answer please? Pretty please with sugar on top... :)
klabranche
Thank you very much! :)
klabranche