Hi guys... I'm building a nested grid and I always get the "No child records to display." error message when I collapse the grid...
My code is this:
| protected void Page_Load(object sender, EventArgs e) |
| { |
| if (! IsPostBack) |
| { |
| string id = "dc945a82-d738-df11-b155-080027bfbfb8"; |
| LlenaGrid(id); |
| this.GridCompromisoHeader.DataBind(); |
| } |
| } |
| private void LlenaGrid(string id) |
| { |
| SqlDataAdapter ADA = new SqlDataAdapter(); |
| StringBuilder sSql = new StringBuilder(); |
| sSql.Append(" SELECT CAMPO1 'CAMPO1', "); |
| sSql.Append(" CAMPO2 'CAMPO2'"); |
| sSql.Append(" FROM TABLA"); |
| sSql.Append(" WHERE"); |
| sSql.Append(" LLAVE = @id"); |
| SqlCommand sqlcmd = new SqlCommand(sSql.ToString()); |
| SqlParameter sqlParam = new SqlParameter("@id", SqlDbType.NVarChar); |
| sqlParam.Value=id; |
| sqlcmd.Parameters.Add(sqlParam); |
| ADA.SelectCommand = sqlcmd; |
| this.GridCompromisoHeader.DataSource = ObtenerDataTable(ADA); |
| } |
| static DataTable ObtenerDataTable(SqlDataAdapter sqlAda) |
| { |
| SqlConnection sqlCnn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyCnnStr"].ConnectionString); |
| DataTable dt = new DataTable(); |
| try |
| { |
| sqlAda.SelectCommand.Connection = sqlCnn; |
| sqlCnn.Open(); |
| sqlAda.Fill(dt); |
| sqlCnn.Close(); |
| } |
| catch (Exception ex) |
| { |
| if (sqlCnn.State == ConnectionState.Open) |
| { |
| sqlCnn.Close(); |
| } |
| } |
| return dt; |
| } |
| protected void GridCompromisoHeader_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e) |
| { |
| GridDataItem dataItem = ((GridDataItem)(e.DetailTableView.ParentItem)); |
| SqlDataAdapter ADA = new SqlDataAdapter(); |
| StringBuilder sSql = new StringBuilder(); |
| sSql.Append(" SELECT CAMPO1 "); |
| sSql.Append(" FROM TABLA2"); |
| sSql.Append(" WHERE"); |
| sSql.Append(" LLAVE2 = @id"); |
| SqlCommand sqlcmd = new SqlCommand(sSql.ToString()); |
| SqlParameter sqlParam = new SqlParameter("@id", SqlDbType.NVarChar); |
| sqlParam.Value = dataItem["CAMPO1"].Text; |
| sqlcmd.Parameters.Add(sqlParam); |
| ADA.SelectCommand = sqlcmd; |
| try |
| { |
| e.DetailTableView.DataSource = ObtenerDataTable(ADA); |
| } |
| catch (System.Exception ex) |
| { |
| } |
| } |