dropdownlist inside gridview

Posted by Oswaldlily under ASP.NET on 12/17/2012 | Points: 10 | Views : 1181 | Status : [Member] | Replies : 3
table1
name id dept
abc 1 cse
abc 2 it
table2
name gender code
abc male a1
abc female a2
table3
code sender
a1 xy
a1 yz
a2 pq
a2 qr
gridview
name gender sender
abc male,female
all 3 colums shd be in dropdownlist.if name selected correspondin valus shd be in gender colum.if male selected correspondin values shd be in sender colum in dropdownlist.




Responses

Posted by: Ankitsrist on: 12/17/2012 [Member] Starter | Points: 25

Up
0
Down
hello,
i consider u know how to bind dropdownlist with database so i move forward....u have to take name as primary key and so foreign key in other tables......
click on the name( first dropdownlist) so that corresponding aspx.cs page will open then write write in name dropdownlist selected index following code
sqlcommand cmd=new sqlcommand("select gender from table2 where name="+name, con);
sqldataadapter adp=new sqldataadapter();
adp.Fill(ds);
DropDownList2.DataSource = ds;
DropDownList2.DataTextField = "gender";
DropDownList2.DataValueField = "name";
DropDownList2.DataBind();
mark this answer if it helps u....

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 12/17/2012 [Member] Starter | Points: 25

Up
0
Down
or u can write.... sqlcommand cmd=new sqlcommand("select name,gender from table2 where dropdownlist1="'+dropdownlist1.selecteditem.text+'", con);

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Manoj_B on: 12/18/2012 [Member] Starter | Points: 25

Up
0
Down
hii

use the following code.

protected void ddlName_SelectedIndexChanged(object sender, EventArgs e)

{
GridViewRow row = ((DropDownList)sender).Parent.Parent as GridViewRow;
DropDownList Name = (DropDownList)(Gridview1.Rows[row.RowIndex].Cells[1].FindControl("ddlddlName"));
DropDownList Gender = (DropDownList)(Gridview1.Rows[row.RowIndex].Cells[2].FindControl("ddlGender"));

sqlcommand cmd=new sqlcommand("select gender from table2 where name='"+Name"'", con);
sqldataadapter adp=new sqldataadapter();
adp.Fill(ds);
Gender.DataSource = ds;
Gender.DataTextField = "gender";
Gender.DataValueField = "name";
Gender.DataBind();
}


Thanks & Regards
Manoj Kumar

Oswaldlily, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response