GridView Control Click


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?


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alfred A.Commented:
Alfred A.Commented:
Hi something like this


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

.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"];


Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.