Click here to Skip to main content
11,501,561 members (74,336 online)
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 13: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)



Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 12 Jun 2012
Copyright © CodeProject, 1999-2015
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