Hello,
Please see below. I put a asp dropdown list in a cell. When i link the OnSelectedIndexChanged event to a C# function it is never called and the post back is never called either. How do i fix this?
Both events work perfectly if i take the dropdown list outside of the WebHierarchicalDataGrid. Something about the WebHierarchicalDataGrid is stopping the control from firing the C# function.
/***************************ASPX*******************************/
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title>
</head><body> <form id="form1" runat="server"> <ig:WebScriptManager ID="wcm" runat="server" /> <div>
<ig:WebDatePicker ID="WebDatePicker1" runat="server"> <AutoPostBackFlags EnterKeyDown="On" ValueChanged="On" /> </ig:WebDatePicker>
<asp:UpdatePanel ID="UpdatePanel1" runat="server"> <Triggers> <asp:AsyncPostBackTrigger ControlID="btnUpdate" EventName="Click" /> </Triggers>
<ContentTemplate>
<asp:ObjectDataSource ID="ods1" SelectMethod="odsCharts" runat="server" TypeName="dbe.Dashboard" /> <asp:XmlDataSource ID="XmlDataSource1" runat="server" XPath="/LIST/USER" EnableCaching="false" />
<ig:WebHierarchicalDataGrid ID="WebHierarchicalDataGrid1" runat="server" Height="650px" Width="1900px" DataSourceID="XmlDataSource1" Key="LIST" DataKeyFields="UserId" AutoGenerateBands="false" AutoGenerateColumns="false" EnableAjax="false" EnableAjaxViewState="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:Label ID="Label1" runat="server"><%# DataBinder.Eval(((Infragistics.Web.UI.TemplateContainer)Container).DataItem, "Location") %></asp:Label> <asp:Image ID="Image1" runat="server" ImageUrl="<%# pix1().ToString() %>" Height="20" Width="20" /> <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> </ContentTemplate> </asp:UpdatePanel> <asp:button ID="btnUpdate" runat="server" text="Update" /> </div> </form></body></html>
/*************** CS ******************/
public partial class Dashboard : System.Web.UI.Page { public string StartDt { get; set; } public string ConnDb = "Data Source=SHANE-PC;Initial Catalog=test;Persist Security Info=True;User ID=test;Password=test";
protected void Page_Load(object sender, EventArgs e) { try { StartDt = WebDatePicker1.Text; XmlDataSource1.Data = GetCases(StartDt); } 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; }
public DataTable odsCharts() { DataTable dt = new DataTable(); try { dt.Columns.Add("Week", typeof(System.String)); dt.Columns.Add("ActiveX", typeof(System.Int32)); dt.Rows.Add(new object[] { "Week 1", 50 }); dt.Rows.Add(new object[] { "Week 2", 75 }); dt.Rows.Add(new object[] { "Week 3", 25 }); dt.Rows.Add(new object[] { "Week 4", 100 }); } catch (Exception e) {
} return dt;
}
public string pix1() { return "test.jpg"; } }
EDIT: Additionally, if i take out the Update Panel and try it again. I now get the following error message:
Server Error in '/' Application.Object reference not set to an instance of an object.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.Stack Trace:[NullReferenceException: Object reference not set to an instance of an object.] Infragistics.Web.UI.GridControls.ContainerGrid.DataBind() +299 Infragistics.Web.UI.GridControls.WebDataGrid.EnsureDataBound() +172 Infragistics.Web.UI.GridControls.ContainerGrid.EnsureDataBound() +339 Infragistics.Web.UI.GridControls.WebDataGrid.CreateChildControls() +51 System.Web.UI.Control.EnsureChildControls() +102 Infragistics.Web.UI.GridControls.WebDataGrid.EnsureChildControls() +129 Infragistics.Web.UI.GridControls.ContainerGrid.EnsureChildControls() +759 System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +20 System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365 System.Web.UI.Control.FindControl(String id, Int32 pathOffset) +365 System.Web.UI.Page.FindControl(String id) +38 System.Web.UI.Page.ProcessPostData(NameValueCollection postData, Boolean fBeforeLoad) +287 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +878Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.272
But at least i get an event to fire on the client.Can someone please give me a example (no links. i need to see an example written out) of a WebHierarchicalDataGrid which has a couple dropdowns inside and each dropdown will fire c# code and update the dropdown in another cell?
Hello Shane,
If you need further assistance let me know.
I have created a simplified example based (partly) on the code pasted by you in order to test the reported issue.
I was unable to reproduce it with this sample and that is why I have made some modifications which show how to set value of one dropdown list control based on selection from other dropdown list. Both controls are in different grid columns and changes are made on Client-Side.
I am attaching this sample to my message. Test it and let me know what the results are.