Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# DataGridView Forms
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 11-Jun-12 14:54pm
Comments
Sandeep Mewara at 12-Jun-12 2:31am
   
What have you tried so far?
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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();
}
 
}
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

  Permalink  

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

  Print Answers RSS
0 OriginalGriff 295
1 DamithSL 265
2 CPallini 235
3 Maciej Los 190
4 Sergey Alexandrovich Kryukov 174
0 OriginalGriff 5,415
1 DamithSL 4,422
2 Maciej Los 3,820
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,911


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100