Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Apr 25, 2012 08:50 AM by rafemuhammed
Apr 22, 2012 05:23 AM|LINK
I have created 2 gridviews.
In gridview1 the database table is displayed.
The gridview1 is used to show the books list.
It is used to search books.
Once the user chooses the row then that selected row should get displayed in the other
gridview2 with the additional columns->details like date of issue,date of return and other details.
I thought to do the coding for this in button itself by adding button on gridview1.
I tried to do this but still not able to do it .
Can anybody help me out?
Apr 22, 2012 05:55 AM|LINK
Apr 22, 2012 06:27 AM|LINK
this requirement is done thru database sp, means
when you click row on gridview1 then gridview1_SelectedIndexcchanged event fired in this event
just hit the database means call stored procedure in which write the code to retrieve the the details of the selected books then bind the resultset of that sp to the second gridview.
I hope this helps you.
Apr 22, 2012 07:01 AM|LINK
Please show html markup of your gridViews
Apr 22, 2012 07:08 AM|LINK
What you can do is add a LinkButton in your Gridview1 which says details so the user can know what that mean
<asp:LinkButton ID="lnkDetails" Width="55px" runat="server" CommandArgument='<%#Eval("ID")%>' CommandName="Details" Text="Details" />
so in your code behind do the following
Private Sub gridview1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles grdPayOrderDetails.RowCommand
if e.commandName = "Details" then
'bind you second gridview based on id which you bind it as command argument
'you can get it as dim id as string = e.commandArgument
'do the binding
Apr 22, 2012 06:16 PM|LINK
This is the general approach to do it. After enabling Selection in GridView put this code in your code behind.
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
//if you use boundfields or Autogenerate columns, get the book name as
//asumed the booknames are displayed in 1st column.
string bookname = GridView1.SelectedRow.Cells.Text;
// If you display bookName in label- "Label1" in an ItemTemplate get it as
//Label lbl = (Label)(GridView1.SelectedRow.FindControl("Label"));
//string booknmae = lbl.Text;
// you can create sql query using this value of bookname
string qry = "SELECT * FROM yourTable WHERE yourField = '" + bookname + "'";
//if you use a datasourrce - "SqlDataSource1" for databinding the the second grid view
SqlDataSource1.SelectCommand = qry;
//if you databind the gridview2 from code behind you can use the
//above query to retrive data and databind()
By clicking the select link in any row of the 1st GridView, the second GridView will be populated with all the details of the bookname displayed in the row you selected.
Try and respond
Apr 24, 2012 03:10 PM|LINK
You can also use the built-in Select button, and handle SelectedIndexChanged.
Looks like you want a Master/Details setup. Search the web for that for plenty of examples.
Apr 24, 2012 03:19 PM|LINK
Apr 25, 2012 08:50 AM|LINK
Did you visit this?