Click here to Skip to main content
15,894,291 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
Hi,

I have a member registration table where a user will introduce another user and such.I am using registration table to get values.I need to populate second gridview from the result of first gridview column value.I used foreach () but it displays only last result of the query.Please help me to create .
this is my code

protected void Page_Load(object sender, EventArgs e)
{



string id = Session["user"].ToString();
id_user.Text = id;
BindGridview(id);



}
protected void BindGridview(string id)
{
con.Open();
string str = id;
SqlCommand cmd = new SqlCommand("select Member_Name,Id,Gender,Member_DOB,[City],[Join_Date],IntroducerID,Introducer_Name from Member_registration where IntroducerID='" + str + "'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds1);
DataTable ds1 = new DataTable();
da.Fill(ds1);
string CountryId = ds1.Rows[0]["Member_Name"].ToString();

bussgrid.DataSource = ds;
bussgrid.DataBind();
//List<datarow> list = new List<datarow>();



foreach (DataRow row in ds1.Rows)
{

string CountryId = row["Member_Name"].ToString();
//string CountryId = ds1.Rows[0][column].ToString();
SqlCommand cmd = new SqlCommand("select Member_Name,Id,Gender,Member_DOB,[Placement_Side],[City],[Join_Date],IntroducerID,SponsorID,Introducer_Name from Member_registration where Introducer_Name='" + CountryId + "' ", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
//LData.MyDataContext db = new LData.MyDataContext();
// var result = new DataTable();
// var row = result.NewRow();
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dtb = new DataTable();

con.Close();
gv.DataSource = ds;
gv.DataBind();
}
}
}
Posted

1 solution

If you need to populate all the data..then do the following
C#
 DataTable dtb = new DataTable();
foreach (DataRow row in ds1.Rows)
 {
DataSet ds = new DataSet();
 string CountryId = row["Member_Name"].ToString();
 //string CountryId = ds1.Rows[0][column].ToString();
 SqlCommand cmd = new SqlCommand("select Member_Name,Id,Gender,Member_DOB,[Placement_Side],[City],[Join_Date],IntroducerID,SponsorID,Introducer_Name from Member_registration where Introducer_Name='" + CountryId + "' ", con);
 SqlDataAdapter da = new SqlDataAdapter(cmd);
 //LData.MyDataContext db = new LData.MyDataContext();
 // var result = new DataTable();
 // var row = result.NewRow();

 da.Fill(ds);
 
 foreach (DataRow dr in ds.Rows)
 {
   dtb.ImportRows(dr);

 }
  
 con.Close();
 }
 gv.DataSource = dtb;
 gv.DataBind();


Regards,
Dinesh Kumar.V.
 
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