Hello,
I have this project, It has a WebHierarchicalDataGrid with an embedded DropdownBoxList. I placed the XMLDataSource object in the CS file. On selecting the dropdownlist inside the grid, i get a postback to the server however, the data in the grid will vanish unless I call the database server for data and rebind, and the dropdownlist change event will not fire. Only when I retrieve the data on each postback and rebind it, will the grid load and the dropdown event fire. I do not want to rebind the data in the grid, i just want to select an item from the dropdown list and have it call the server and get a list of data. How do i fix this?
/********************** ASPX ***********************/
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="650px" Width="1900px" Key="LIST" DataKeyFields="UserId" AutoGenerateBands="false" AutoGenerateColumns="false"> <Columns> <ig:BoundDataField DataFieldName="UserId" Key="UserId" Header-Text="CategoryID" Width="200px"><Header Text="CategoryID"></Header></ig:BoundDataField> <ig:BoundDataField DataFieldName="Names" Key="Names" Header-Text="Names" Width="200px"><Header Text="Names"></Header></ig:BoundDataField> <ig:BoundDataField DataFieldName="Location" Key="Location" Header-Text="Location" Width="200px"><Header Text="Location"></Header></ig:BoundDataField> <ig:TemplateDataField Key="Image" Width="525px"> <ItemTemplate> <asp:DropDownList ID="QType" runat="server" AutoPostBack="true" OnSelectedIndexChanged="SelectionChanged"> <asp:ListItem Text="True/False" Value="1"></asp:ListItem> <asp:ListItem Text="Multiple Choice" Value="2"></asp:ListItem> <asp:ListItem Text="Multiple Answer" Value="3"></asp:ListItem> </asp:DropDownList> </ItemTemplate> <Header Text="Image" /> </ig:TemplateDataField> <ig:TemplateDataField Key="Chart" Width="300"> <ItemTemplate> <igchart:UltraChart ID="UltraChart1" runat="server" EmptyChartText="Data Not Available." Version="11.2" DataSourceID="ods1" Height="50px" Width="50px"> </igchart:UltraChart> </ItemTemplate> </ig:TemplateDataField> </Columns> <Bands> <ig:Band AutoGenerateColumns="false" DataMember="CASE" DataKeyFields="CaseId" ShowFooter="False"> <Columns> <ig:BoundDataField DataFieldName="CaseId" Key="CaseId" Header-Text="CaseId" Width="200px"><Header Text="CaseId"></Header></ig:BoundDataField> <ig:BoundDataField DataFieldName="Subject" Key="Subject" Header-Text="Subject" Width="200px"><Header Text="Subject"></Header></ig:BoundDataField> <ig:BoundDataField DataFieldName="CreatedDate" Key="CreatedDate" Header-Text="CreatedDate" Width="200px"><Header Text="CreatedDate"></Header></ig:BoundDataField> </Columns> </ig:Band> </Bands> </ig:WebHierarchicalDataGrid>
/*************************CS**********************/
protected void Page_Load(object sender, EventArgs e) { try { StartDt = WebDatePicker1.Text; if (!Page.IsPostBack) { using (XmlDataSource xmlDataSource = new XmlDataSource()) { xmlDataSource.XPath = @"/LIST/USER"; xmlDataSource.EnableCaching = false; xmlDataSource.Data = GetCases(StartDt); WebHierarchicalDataGrid1.GridView.ClearDataSource(); WebHierarchicalDataGrid1.DataSource = xmlDataSource; WebHierarchicalDataGrid1.DataBind(); } } } catch (Exception exc) { } } protected void SelectionChanged(object sender, EventArgs e) { DropDownList d = (DropDownList)sender; } private string GetCases(string date) { DataRow dataRow; DataTable dataTable = new DataTable(); string strSQL = "dbo.getCases"; string result = ""; try { using (SqlConnection connection = new SqlConnection(ConnDb)) { using (SqlCommand command = new SqlCommand(strSQL, connection)) { command.CommandType = CommandType.StoredProcedure; command.Parameters.AddWithValue("@CreatedDate", date); using (SqlDataAdapter dataAdapter = new SqlDataAdapter(command)) { dataAdapter.Fill(dataTable); } if (dataTable.Rows.Count > 0) { dataRow = dataTable.Rows[0]; result = dataRow[0].ToString(); } } } } catch (Exception e) { } return result; }
The WebHierarchicalDataGrid requires access to its data source on every post back. You can also set EnableDataViewState property to "true". Please keep in mind that this is not recommended approach for WebHierarchicalDataGrid. The below links will give more details on this property:
<http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/?page=Infragistics4.Web.v11.2~Infragistics.Web.UI.GridControls.WebHierarchicalDataGrid~EnableDataViewState.html>
<http://community.infragistics.com/forums/p/47419/253192.aspx>
I hope this helps.
I am just following up to see if you need any assistance with this matter.