This is a migrated thread and some comments may be shown as answers.

Radgrid control rowexpander not enabled

2 Answers 79 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Larry
Top achievements
Rank 1
Larry asked on 22 Jul 2013, 04:07 PM
I have a hierarchal radgrid control that consists of a master table and 2 detail tables which sit on a web form.  The web form also has a text box on it that's used for querying the info you want shown in the grid.  Initially the radgrid is not visible, so all the user sees is the text box when the app is launched.  Upon data entry (same page is launched again through a response.redirect "Page name" in a button click event), the grid becomes visible and the data is loaded and bound to the grid through the NeedDataSource method. However when the page returns, the master table data is being shown correctly in the grid, but the row expander to get to the detail tables is not enabled which prevents the user from drilling down any further.  I've got events to assign the detail datasource when the row is expanded, so I know it works.  I've done test on the grid where I load the grid on the initial load based on some hard coded criteria and I'm able to drill down without having to set any other properties.  Why is it that I can't do this based on user submitted data in a click event?

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 23 Jul 2013, 09:31 AM
Hi Larry,

Please have a look at the below code example that i tried,its working fine at my end,i can get the child tables on expand.

ASPX:
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" onclick="Button1_Click" />
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="False"
    OnDetailTableDataBind="RadGrid1_DetailTableDataBind" >
    <MasterTableView DataKeyNames="CustomerID" HierarchyLoadMode="ServerOnDemand">
        <DetailTables>
            <telerik:GridTableView DataKeyNames="OrderID" Name="Orders">
                <DetailTables>
                    <telerik:GridTableView DataKeyNames="OrderID" Name="OrderDetails" >
                        <Columns>
                            <telerik:GridBoundColumn  HeaderText="Unit Price" HeaderButtonType="TextButton"
                                DataField="UnitPrice">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn  HeaderText="Quantity" HeaderButtonType="TextButton"
                                DataField="Quantity">
                            </telerik:GridBoundColumn>
                            <telerik:GridBoundColumn  HeaderText="Discount" HeaderButtonType="TextButton"
                                DataField="Discount">
                            </telerik:GridBoundColumn>
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridBoundColumn HeaderText="OrderID" HeaderButtonType="TextButton"
                        DataField="OrderID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn  HeaderText="Date Ordered" HeaderButtonType="TextButton"
                        DataField="OrderDate" UniqueName="OrderDate" DataFormatString="{0:D}">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Freight" HeaderButtonType="TextButton"
                        DataField="Freight" UniqueName="Freight">
                    </telerik:GridBoundColumn>
                </Columns>
            </telerik:GridTableView>
        </DetailTables>
        <Columns>
            <telerik:GridBoundColumn HeaderText="CustomerID" HeaderButtonType="TextButton"
                DataField="CustomerID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn  HeaderText="Contact Name" HeaderButtonType="TextButton"
                DataField="ContactName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn  HeaderText="Company" HeaderButtonType="TextButton"
                DataField="CompanyName">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>


C#:
protected void Page_Load(object sender, EventArgs e)
   {
       if (!IsPostBack)
       {
           RadGrid1.Visible = false;
       }
   }   
 
   protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
   {
       GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
       switch (e.DetailTableView.Name)
       {
           case "Orders":
               {
                   string CustomerID = dataItem.GetDataKeyValue("CustomerID").ToString();
                   e.DetailTableView.DataSource = GetDataTable("SELECT * FROM Orders");
                   break;
               }
 
           case "OrderDetails":
               {
                   string OrderID = dataItem.GetDataKeyValue("OrderID").ToString();
                   e.DetailTableView.DataSource = GetDataTable("SELECT * FROM [Order Details] WHERE OrderID = " + OrderID);
                   break;
               }
       }
   }
 
   public DataTable GetDataTable(string query)
   {
       String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
       SqlConnection conn = new SqlConnection(ConnString);
       SqlDataAdapter adapter = new SqlDataAdapter();
       adapter.SelectCommand = new SqlCommand(query, conn);
 
       DataTable myDataTable = new DataTable();
 
       conn.Open();
       try
       {
           adapter.Fill(myDataTable);
       }
       finally
       {
           conn.Close();
       }
 
       return myDataTable;
   }
  
    protected void Button1_Click(object sender, EventArgs e)
   {
       RadGrid1.Visible = true;
       string textboxtext = TextBox1.Text;
       if (textboxtext == "OTTIK")
       {       
        RadGrid1.DataSource = GetDataTable("SELECT * FROM Customers where CustomerID='"+textboxtext+"'");
        RadGrid1.Rebind();          
       }
       else if (textboxtext == "FOLIG")
       {           
           RadGrid1.DataSource = GetDataTable("SELECT  * FROM Customers where CustomerID='" + textboxtext + "'");
           RadGrid1.Rebind();
       }
   }

Thanks,
Princy
0
Larry
Top achievements
Rank 1
answered on 23 Jul 2013, 05:19 PM
Hi Princy,
Your example worked for me as well(in a new test program), but my original program still has the same issue.  My program is a bit more abstract, so it would be difficult for me to post the code.  There are a few things that I'm doing differently than in your example, which may or may not be contributing to my problem.  In my code, I'm using an object data source instead of a sql data source. A seperate data access class with methods to return an IList which I'm using as the binding object instead of  a method inside the web form using a data table as the binding object.  I changed my code to do the binding on postback in the click event like your example instead of launching the page again and binding with the NeedDataSource method, but that didn't help.  I'm going to play around with the datasource types and binding objects to see if that does anything.  Thanks for your help though.
Tags
Grid
Asked by
Larry
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Larry
Top achievements
Rank 1
Share this question
or