Grid view Dropdown list data binding error

mark455

New Member
Am using the below code to bind the dropdown data from another table. And also refer that control name using rowindex. But it always return null.And also return the error message. \[code\] `Object reference not set to an instance of an object.` \[/code\]Am using the two method, but both return the control name nullFirst code:\[code\] protected void GridView2_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Control ctrl = e.Row.FindControl("DDL_STATUS_FT"); //It always return null if (ctrl != null) { DropDownList dd = ctrl as DropDownList; DataSet7TableAdapters.sp_getall_trv_masterTableAdapter TA = new DataSet7TableAdapters.sp_getall_trv_masterTableAdapter(); DataSet7.sp_getall_trv_masterDataTable DS = TA.GetData(); dd.DataTextField = "fld_TName"; dd.DataValueField = "fld_id"; dd.DataSource = DS; dd.DataBind(); } } } \[/code\]Second :\[code\] In databind functionif (DS.Rows.Count > 0) { GridView2.DataSource = DS; GridView2.DataBind(); foreach (GridViewRow grdRow in GridView2.Rows) { DataSet7TableAdapters.sp_getall_trv_masterTableAdapter TA1 = new DataSet7TableAdapters.sp_getall_trv_masterTableAdapter(); DataSet7.sp_getall_trv_masterDataTable DS1 = TA1.GetData(); // Nested DropDownList Control reference is passed to the DrdList object. This will allow you access the properties of dropdownlist placed inside the GridView Template column. DropDownList drdList = (DropDownList)(GridView2.Rows[grdRow.RowIndex].Cells[4].FindControl("DDL_STATUS_FT"));//It always return null // DataBinding of nested DropDownList Control for each row of GridView Control. drdList.DataSource = DS1; drdList.DataValueField = "fld_id"; drdList.DataTextField = "fld_TName"; drdList.DataBind(); } }\[/code\]Please help me to do this..
 
Back
Top