Note that there are some explanatory texts on larger screens.

plurals
  1. POASP.NET Nested GridView, DataItem returns null in child GridView's RowDataBound Event
    primarykey
    data
    text
    <p>In a nested GridView (GridView inside a template column of parent GridView). I am binding child GridView to a DataTable in parent GridView's RowDataBound event. this works as it should. But the problem i am facing is in Child GridView's RowDataBound Event, when i try to access e.Row.DataItem property it returns null. I am expecting it to return DataRowView Type. which i will then use to set values of TextBox's.</p> <p>Parent GridViewId = gvProductOptionGrps and Child GridViewId = gvProductOptions </p> <p>Parent GridViews RowDataBound Event.</p> <pre><code> protected void gvProductOptionGrps_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { //ProductOptionGrps TextBox txtProductOptionGrpSortOrder = (TextBox)e.Row.FindControl("txtProductOptionGrpSortOrder"); Label lblProductOptionGrpName = (Label)e.Row.FindControl("lblProductOptionGrpName"); DataRowView drv = (DataRowView)e.Row.DataItem; txtProductOptionGrpSortOrder.Text = drv["SortOrder"].ToString(); lblProductOptionGrpName.Text = drv["Name"].ToString(); //ProductOptions SqlCommand sqlCmd = new SqlCommand(); sqlCmd.CommandText = "SELECT a.ProductOptionId,a.SortOrder,b.Name,b.PriceGBP" + " FROM ProductOptionGrpProductOptions a" + " INNER JOIN ProductOptions b ON a.ProductOptionId=b.ProductOptionId" + " WHERE a.ProductOptionGrpId=@ProductOptionGrpId" + " ORDER BY a.SortOrder"; sqlCmd.CommandType = CommandType.Text; sqlCmd.Parameters.Add("@ProductOptionGrpId", SqlDbType.UniqueIdentifier).Value = new Guid(drv["ProductOptionGrpId"].ToString()); _fl.ConnectToSQLServer(); sqlCmd.Connection = _fl.GetActiveSQLServerConnection(); DataTable dtProductOptions = new DataTable(); dtProductOptions.Load(sqlCmd.ExecuteReader()); GridView gv = (GridView)e.Row.FindControl("gvProductOptions"); gv.DataSource = dtProductOptions; gv.DataBind(); _fl.DisconnectFromSQLServer(); } } protected void gvProductOptions_RowDataBound(object sender, GridViewRowEventArgs e) { TextBox txtProductOptionSortOrder = (TextBox)e.Row.FindControl("txtProductOptionSortOrder"); TextBox txtPriceGBP = (TextBox)e.Row.FindControl("txtPriceGBP"); DataRowView drv = (DataRowView)e.Row.DataItem;//returns null txtProductOptionSortOrder.Text = drv["SortOrder"].ToString();//Error txtPriceGBP.Text = drv["PriceGBP"].ToString();//Error } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload