Selectedindex in datadropList in datagrid
-
I want to set the selectedindex of a datadroplist in a datagrid. I have following method to get which index to display: public int SetNewCompanyIndex(object cname) { int com = int.Parse(cname.ToString()); int companyID = com - 1; return companyID; } Next, I have: " runat="server" > But this does not display the DDl. If I remove SelectedIndex from the above code, I can display the DDL, but of course, it does not set the proper selected index. So how can I make DDL to display the chosen Selected index thanks
-
I want to set the selectedindex of a datadroplist in a datagrid. I have following method to get which index to display: public int SetNewCompanyIndex(object cname) { int com = int.Parse(cname.ToString()); int companyID = com - 1; return companyID; } Next, I have: " runat="server" > But this does not display the DDl. If I remove SelectedIndex from the above code, I can display the DDL, but of course, it does not set the proper selected index. So how can I make DDL to display the chosen Selected index thanks
Hi hasan well, shld b an easy task, try d following -
private void dg_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) { DropDownList lst=(DropDownList)e.Item.FindControl("ddl"); if(lst!=null) lst.SelectedIndex=SetNewCompanyIndex(e.Item.ItemIndex+1); }
here dg is datagrid n ddl is the dropdownlist UTSAV