Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi, masters..

please help me, how to fill the datagridview2 with information from datagridivew1. Example, when i input idproduct from dgv1 in dgv2, dgv2 can show automatically the product name (product name stored in dgv1)..

please help me to do this sir. i am very new to C#
Posted
Comments
Sandeep Mewara 12-Jun-12 2:31am    
What have you tried so far?

i give u an example...

design sql table as below..[set primary key to city]

country city

india chennai
india bangalore

india hydrabad

usa newyork

usa washington

china beiging


set AutopostBack property to True for both Countrydropdownlist and citydropdownlist.

now write query as


function country()
{
string strSQL;
string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(dbConn);
sqlConn.Open();
strSQL = "SELECT select country from tablename ";
SqlCommand cmdFloorType = new SqlCommand(strSQL, sqlConn);
SqlDataReader drFloor = cmdFloorType.ExecuteReader();
while (drFloor.Read())
{
countryDrpdownlist.Items.Add( drFloor[0]).ToString();

}

sqlConn.Close();
}

call that function into page_load event

page_load()
{
if(!Ispostback)
{
country()
}
now double click countrydropdownlist and write coding

ddlcountry_selectedItem()
{
string strSQL;
string dbConn = ConfigurationManager.ConnectionStrings["CMC"].ConnectionString;
SqlConnection sqlConn = new SqlConnection(dbConn);
sqlConn.Open();
strSQL = "SELECT select City from tablename where Country='"+countryDropdowlist.selectedItem.Tostring()+"' ";
SqlCommand cmdFloorType = new SqlCommand(strSQL, sqlConn);
SqlDataReader drFloor = cmdFloorType.ExecuteReader();
while (drFloor.Read())
{
cityDrpdownlist.Items.Add( drFloor[0]).ToString();

}

sqlConn.Close();
}

}
 
Share this answer
 
 
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