Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
945
Why does the grid vanish on a postback from a embedded control?
posted

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;
        }

Parents Reply Children
No Data