asp.net C# gridview Problm

Posted by mcanarendrachoudhary-10608 under Regular Expressions on 6/20/2011 | Points: 10 | Views : 1394 | Status : [Member] | Replies : 2
Sir ,
I have a grid view . and by clicking on Edit Button there are two dropdownlist shows in one row .i want to show data in dropdownlist_2 on selected_indexchanged event of dropdownlist_1.how can i do this ?




Responses

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi
I guess you are able to load data into your first dropdown list.
If not try to use row data bound event to load the data in the 1st dropdownlist,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

{
DropDownList ddlone=e.Row.FindControl("ID of the 1st dropdownlist ") as DropDownList;
// assign the datasource here then databind.
}


Now in the ASPX page from for the 1st dropdownlist try to set the autopostback property to true.
then add selectedindex changed event handler like
AutoPostBack="true" OnSelectedIndexChanged="cmb_SelectedIndexChanged"

in the code behind file
protected void cmb_SelectedIndexChanged(object sender, EventArgs e)

{
int currentindex = ((GridViewRow)((Control)sender).Parent.NamingContainer).RowIndex;
DropDownList ddltwo=GridView1.Rows[currentindex ].FindControl("ID of the 2nd dropdownlist ") as DropDownList;
// assign the datasource for the 2nd one here then databind.
}

Thanks,
Debata

mcanarendrachoudhary-10608, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/21/2011 [Member] Starter | Points: 25

Up
0
Down
try this

http://www.codeproject.com/KB/webforms/Editable_GridView.aspx?msg=3600027

Thanks&Regards
LakshmiNarayana Nalluri.

mcanarendrachoudhary-10608, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response