Click here to Skip to main content
15,897,518 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have a GridView with 4columns.
Id Vendor_Name Asset_Type Button
1 Tech_M Mouse Button1

2 Religare Keyboard Button1
3 Samsung Mobiles Button1
My problem is how when i will click button 1 of row 1 the corresponding Vendor_Name Tech_M will display in the other Ratecard.Aspx page. Similarly when i Click button 1 of row 2 the i want to get Religare in the Label of my Ratecard.aspx page. How will i do this. kindly help.
Posted

1 solution

This simply depends on your database design.
You need to have table like this,
Item
+ ItemID | int | PK
+ ItemName | varchar

Vendor
+ VendorId | int | PK
+ VendorName | varchar
+ ItemId | int | FK

Now the query,
SELECT * FROM Item i, Vendor v WHERE i.VendorId = v.VendorId AND i.ItemId = @itemId
here @itemId is passed from your gridview.

And the code,
C#
SqlCommand cmd = new SqlCommand(SELECT * FROM Item i, Vendor v WHERE i.VendorId = v.VendorId AND i.ItemId = @itemId, conObject);
cmd.Paramaters.AddWithValue("@itemId", itemId);  // your item id i.e Samsung = 1, Nokia = 2 etc.
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

foreach(DataRow dr in dt.Rows)
{
    YourLabel.Text = dr["YourColumn"].ToString();
}


Hope you got the idea.. :)

-KR
 
Share this answer
 

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