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
125
Ultrawebgrid not displaying correct data on first button click.
posted

Hi,
I am using ultrawebgrid in my asp.net application.
I have two combobox 1)Month 2)Year and a Button.
Below that I placed the ultrawebgrid control.
At the InitializeGridDataSource event I fill the ultrawebgrid with data.
I called the sql connection add the relation in dataset and
assign dataset to Datasource property, this works fine.
Now I select the different month from the combo and click on the refresh button
here ultrawebgrid can not show the updated record but this behaviour only happen at the first click of the button if i again click the refresh button then it is showing correct data.
Though the data is correct in dataset at the first click.

Please find below the code of InitializeDataSource event.

 protected void ugMachineList_InitializeDataSource(object sender, Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs e)
    {
        if (!IsPostBack)
            FillGrid();
        else
        {
            //When user click on the "+" sign autopost back event is fired
            //which again call the fillgrid function to avoid this
            //we add the Sitecommission and Database (which are selected by user information) in session table
            //and use that tables to show data in grid.
           
            ugMachineList.DataSource = null;
            if (dtDBTable == null )
            {
                dtDBTable = (DataTable)Session["DBTable"];
                if (dtDBTable != null && dtDBTable.Rows.Count > 0)
                {
                    DataRow[] dtRows = dtDBTable.Select("[Select]=true");

                    if (dtRows != null && dtRows.Length > 0)
                    {
                        if (!dtDBFilter.Columns.Contains("Select"))
                            dtDBFilter.Columns.Add("Select");
                        if (!dtDBFilter.Columns.Contains("DatabaseName"))
                            dtDBFilter.Columns.Add("DatabaseName");
                        if (!dtDBFilter.Columns.Contains("DBId"))
                            dtDBFilter.Columns.Add("DBId");
                        foreach (DataRow dtRow in dtRows)
                        {
                            dtDBFilter.ImportRow(dtRow);
                        }
                    }
                }
            }
            //if(dtDBFilter==null && dtDBFilter.Rows.Count<=0 )
            //    dtDBFilter =(DataTable)Session["DBFilter"];
            if (dtSiteCommTransinfo == null)
                dtSiteCommTransinfo = (DataTable)Session["Transaction"];

            //if (dtDBFilter != null && dtDBFilter.Rows.Count > 0)
            //    Session["DBFilter"] = dtDBFilter;
           
            if (!dtSet.Tables.Contains("Table1"))
            {
                dtSet.Tables.Add(dtDBFilter.Copy());
            }
            if (!dtSet.Tables.Contains("Table2"))
            {
                dtSet.Tables.Add(dtSiteCommTransinfo.Copy());
            }
            dtSet.Relations.Add("Relation", dtSet.Tables[0].Columns["DBId"], dtSet.Tables[1].Columns["DBId"]);
            ugMachineList.DataSource = dtSet;

        }
    }

FillGrid Code


dtDBTable = (DataTable)Session["DBTable"];
            if (dtDBTable != null && dtDBTable.Rows.Count > 0)
            {
                DataRow[] dtRows = dtDBTable.Select("[Select]=true");

                if (dtRows != null && dtRows.Length > 0)
                {
                    if (!dtDBFilter.Columns.Contains("Select"))
                        dtDBFilter.Columns.Add("Select");
                    if (!dtDBFilter.Columns.Contains("DatabaseName"))
                        dtDBFilter.Columns.Add("DatabaseName");
                    if (!dtDBFilter.Columns.Contains("DBId"))
                        dtDBFilter.Columns.Add("DBId");
                    if (dtDBFilter != null && dtDBFilter.Rows.Count<=0)
                    {
                        foreach (DataRow dtRow in dtRows)
                        {
                            dtDBFilter.ImportRow(dtRow);
                        }
                    }
                }
                for (int iCount = 0; iCount <= dtDBFilter.Rows.Count - 1; iCount++)
                {
                    if (Convert.ToString(dtDBFilter.Rows[iCount]["DatabaseName"]) == "KIWI1")//For Database Coinop
                    {
                        //add the code for BooBoo database.
                        // CommonSettings.DBName = "Test";
                        //connectString = "Data Source=58.108.208.65;Initial Catalog=test;Persist Security Info=True;User ID=test;password=Lindsay";
                        connectString = ConfigurationManager.ConnectionStrings["KIWI1"].ConnectionString;
                        intMonth  = Convert.ToInt32(cmbmonth.SelectedValue);
                        intYear = Convert.ToInt32(cmbyear.SelectedValue);
 
                        dttemptable = GetGridData(connectString, intMonth , intYear );
                        if (null != dttemptable && dttemptable.Rows.Count > 0)//for Test database ,DBId 2
                        {
                            if (dtSiteCommTransinfo == null)
                            {
                                dtSiteCommTransinfo = dttemptable;
                            }
                            else
                            {
                                for (int irowCount = 0; irowCount <= dttemptable.Rows.Count - 1; irowCount++)
                                {
                                    dtSiteCommTransinfo.ImportRow(dttemptable.Rows[irowCount]);
                                }

                            }
                            if (null != dtSiteCommTransinfo && dtSiteCommTransinfo.Rows.Count > 0)
                            {
                                if (dtSiteCommTransinfo.Columns.Contains("DBId"))
                                {
                                    for (int i = 0; i <= dtSiteCommTransinfo.Rows.Count - 1; i++)
                                    {
                                        if (dtSiteCommTransinfo.Rows[i]["DBId"].ToString() == "")
                                            dtSiteCommTransinfo.Rows[i]["DBId"] =1;
                                    }
                                }
                                else
                                {
                                    dtSiteCommTransinfo.Columns.Add("DBId");
                                    for (int i = 0; i <= dtSiteCommTransinfo.Rows.Count - 1; i++)
                                    {
                                        dtSiteCommTransinfo.Rows[i]["DBId"] = 1;
                                    }
                                }

                            }

                        }

                    }


}

 ugMachineList.DataSource = null;
               // ugMachineList.DataSource = null;
                //dtTransactionInfo.Merge(dtBOOBOO);
                if (dtSiteCommTransinfo != null && dtSiteCommTransinfo.Rows.Count > 0)
                {
                    Session["Transaction"] = dtSiteCommTransinfo;

                    if (dtDBFilter != null && dtDBFilter.Rows.Count > 0)
                        Session["DBFilter"] = dtDBFilter;

                    if (!dtSet.Tables.Contains("Table1"))
                    {
                        dtSet.Tables.Add(dtDBFilter.Copy());
                    }
                    if (!dtSet.Tables.Contains("Table2"))
                    {
                        Session["Transaction"] = dtSiteCommTransinfo;
                        dtSet.Tables.Add(dtSiteCommTransinfo.Copy());
                    }

                    dtSet.Relations.Add("Relation", dtSet.Tables[0].Columns["DBId"], dtSet.Tables[1].Columns["DBId"]);
                    ugMachineList.DataSource = dtSet;
                    ugMachineList.DataBind();
                   
                }
                else
                {
                    lblMessage.Text = "No Data Found.Please select the different month.";
                    lblMessage.Visible = true;
                    ugMachineList.Visible = false;
                   
                 
                }
             
            }


Please let me know why the grid not showing correct data on first button click.
I have added the scriptmanager and updatepanel control.

Regards