0

I have a problem with gridview, I am using a gridview and listview on a page, when I select a row in the gridview I want to insert the data into the listview based on selection in the gridview. I am using a primary key in gridview.

PLease help me out

1
  • 3
    Straight from MSDN, showing how to drill-down for information based on gridview selection. Commented Oct 12, 2011 at 21:00

2 Answers 2

3

This is also called "Master-Detail".

You can find a great tutorial here.

In short, you need to make the row selectable.

<asp:GridView ID="ProductsGrid" runat="server"
    AutoGenerateColumns="False" DataKeyNames="ProductID"
    DataSourceID="AllProductsDataSource" EnableViewState="False">
    <Columns>
        <asp:CommandField ShowSelectButton="True" />
        <asp:BoundField DataField="ProductName"
         HeaderText="Product" SortExpression="ProductName" />
        <asp:BoundField DataField="UnitPrice"
          DataFormatString="{0:c}" HeaderText="Unit Price"
          HtmlEncode="False" SortExpression="UnitPrice" />
    </Columns>
</asp:GridView>

This is done with <asp:CommandField ShowSelectButton="True" /> in the code above.

The next step is to add you DetailsView to be binded to the selected element of the master gridview. This can be done because the selection return the primary key of the element, from there you can load the detail.

This do a PostBack, if you want you can use Ajax and remove the PostBack flickering.

Sign up to request clarification or add additional context in comments.

Comments

1

I believe the select on the gridview should fire off the event SelectedIndexChanged(). You would use that event to create the datasource for your listview and then bind the datasource to your listview.

1 Comment

+1: It's a good answer, but in the future you should post a small example to demonstrate, especially since OP did not post any example code.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.