GridView Control Click

Hi,

I have a Gridview control bound to data returned from a database.  I want to be able to click on one of the Gridview rows to bring up more information.  Ideally, using some javascript to slide down the further information.  But if that's not possible/too complicated then taking the user to another form and passing the record ID would be fine.

Anyone able to assist?

Cheers...

John
johnnyc82Asked:
Who is Participating?
 
drypzConnect With a Mentor Commented:
Hi something like this

.aspx

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="grid"
            DataKeyNames="ID" OnRowCommand="GrieView1_RowCommand" >
            <Columns>
                <asp:TemplateField HeaderText="Name">
                    <ItemTemplate>
                        <asp:Label ID="lblName" runat="server" Text='<%#Eval("Name") %>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField HeaderText="Address">
                    <ItemTemplate>
                        <asp:Label ID="lblAddress" runat="server" Text='<%#Eval("Address")%>'></asp:Label>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:TemplateField>
                    <ItemTemplate>
                        <asp:Button ID="btnEdit" runat="server" Text="Edit" CommandName="EDITRECORD"
                            CommandArgument='<%#Container.DataItemIndex %>' />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
        </asp:GridView>


.CS (Codebehind)

    protected void gridCategory_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EDITRECORD")
        {
            //you can get the ID of the row like this
            int index = Convert.ToInt32(e.CommandArgument);
            GridViewRow gridRow = GridView1.Rows[index];

            int id = (int)GridView1.DataKeys[index]["ID"];

            Response.Write(id.ToString());
        }
    }

Open in new window

0
 
Alfred A.Commented:
0
 
Alfred A.Commented:
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.