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?
Thanks.
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.
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
End if
End sub
Please "Mark as Answer" if this post helps.Thank You :)
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[0].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;
GridView2.DataBind();
//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
Kindly mark this post as "Answer", if it helped you.
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.
Superguppie.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
IAmateur
Member
96 Points
388 Posts
Gridview1 row display on gridview 2
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?
Thanks.
Time to go Long way...
rafemuhammed
Member
302 Points
97 Posts
Re: Gridview1 row display on gridview 2
Apr 22, 2012 05:55 AM|LINK
See this..
http://forums.asp.net/t/1328980.aspx/1
rafes.net
ZeeshanAnsar...
Participant
878 Points
264 Posts
Re: Gridview1 row display on gridview 2
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.
Please 'Mark as Answer' if this post helps you.
basheerkal
Star
10672 Points
2426 Posts
Re: Gridview1 row display on gridview 2
Apr 22, 2012 07:01 AM|LINK
Hi
Please show html markup of your gridViews
(Talk less..Work more)
AmalO.Abdull...
Contributor
3116 Points
764 Posts
Re: Gridview1 row display on gridview 2
Apr 22, 2012 07:08 AM|LINK
Hi,
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
End if
End sub
basheerkal
Star
10672 Points
2426 Posts
Re: Gridview1 row display on gridview 2
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[0].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; GridView2.DataBind(); //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
(Talk less..Work more)
superguppie
All-Star
48225 Points
8679 Posts
Re: Gridview1 row display on gridview 2
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.
Please remember to click “Mark as Answer” on the post that helps you. This can be beneficial to other community members reading the thread.
When all you've got is a Hammer, Every Problem looks like a Nail. Michael Swain.
amit.jain
Star
11225 Points
1815 Posts
Re: Gridview1 row display on gridview 2
Apr 24, 2012 03:19 PM|LINK
Refer http://csharpdotnetfreak.blogspot.com/2008/11/pouplating-multiple-detailsview-based.html
amiT jaiN
ASP.NET C# VB Articles And Code Examples
rafemuhammed
Member
302 Points
97 Posts
Re: Gridview1 row display on gridview 2
Apr 25, 2012 08:50 AM|LINK
Did you visit this?
http://forums.asp.net/t/1328980.aspx/1
rafes.net