Click here to Skip to main content
15,936,709 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Team ,

In my project there is one requirement to store order details in database. The key factor to locate and select order details are {DealerId ,DealerName , [Order Details ..] } .
For the same I have designed one form which had two gridview one to display dealer name and another to display order details. If user have selected the dealer name from the first gridview and order details from the second grid view then on the click of SAVE I need to store {DealerId, DealerName, [Order Details ..] } on to database.

My Questions are :
1) How to identify DealerId from dealername ?
2) How to save two grids selected information in database ?

Hope this helps
Posted
Updated 19-Apr-12 20:44pm
v2
Comments
Sandeep Mewara 20-Apr-12 1:22am    
Again, what have you tried? Share your effort and the place where you are stuck/having issues. Be specific.
Use the "Improve question" link to edit your question and provide better information.

 
Share this answer
 
There is option in "GridView" to give "DataKeyNames".
This "DataKeyNames" itself suggests what it is.
For your requirement you can store the "DealerId" in it.
Code is like below
C#
<asp:gridview id="grdDealerDetails" runat="server" autogeneratecolumns="False" allowpaging="true" datakeynames="DealerId" .....></asp:gridview>

The DataKeyNames is the same as of the primary key name of the dealer table.

And when you save the details to the database you can get the PK of the selected row in GridView automatically. To get the "DealerId" follow the code below in RowUpdating event.
C#
protected void grdDealerDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
  int DealerId = Convert.ToInt32((grdDealerDetails.DataKeys[e.RowIndex]).Value.ToString());
        // Now you get the DealerId, do whatever you want with that.
}
 
Share this answer
 
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900