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

How To Clear the rad grid

4 Answers 550 Views
Grid
This is a migrated thread and some comments may be shown as answers.
mohamed
Top achievements
Rank 1
mohamed asked on 10 May 2011, 05:53 AM
how to clear the radgrid .after bind the record

SqlConn = ObjDBHelp.GetOpenConnection();

            DataTable dt1 = new DataTable();
            DataTable dt2 = new DataTable();
            SqlDataAdapter sqladp = new SqlDataAdapter();

            try
            {
                if (showinactive == "0")
                {
                    string selectQuery = "SELECT AssetName, SerialNumber, Asset_UserID,Asset_Inactive FROM [Assets] where Asset_Inactive>0 order by AssetName asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                    sqladp.Fill(dt1);
                    int i = dt1.Rows.Count;
                    dt1 = null;

                    if (i > 0)
                    {
                        selectQuery = "SELECT a.AssetID,a.AssetName,a.SerialNumber,a.Asset_UserID,b.ppl_Name,a.Asset_Inactive FROM [Assets] a , People b " +
                                      "where a.Asset_UserID=b.PeopleID  order by AssetName asc";
                        sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                        sqladp.Fill(dt2);
                        GridColumn chkbox = RadGrid1.MasterTableView.GetColumnSafe("Asset_Inactive");
                        chkbox.Visible = true;
                    }
                    else
                    {
                        selectQuery = "SELECT a.AssetID,a.AssetName,a.SerialNumber,a.Asset_UserID,b.ppl_Name,a.Asset_Inactive FROM [Assets] a , People b " +
                                      "where a.Asset_UserID=b.PeopleID  order by AssetName asc";
                        sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                        sqladp.Fill(dt2);
                        RadGrid1.DataSource = dt2;
                        RadGrid1.DataBind();
                        GridColumn chkbox = RadGrid1.MasterTableView.GetColumnSafe("Asset_Inactive");
                        chkbox.Visible = false;
                    }
                }
                else
                {
                    string selectQuery = "SELECT AssetName, SerialNumber, Asset_UserID,Asset_Inactive FROM [Assets] where Asset_Inactive>0 order by AssetName asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                    sqladp.Fill(dt1);
                    int i = dt1.Rows.Count;
                    dt1 = null;

                    if (i > 0)
                    {
                        selectQuery = "select  a.AssetID,a.AssetName,a.SerialNumber,a.Asset_UserID,b.ppl_Name,a.Asset_Inactive FROM [Assets] a , People b  " +
                                            "where a.Asset_UserID=b.PeopleID and a.Asset_Inactive=1 order by AssetName asc";
                        sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                        sqladp.Fill(dt2);
                        showinactive = "0";
                    }
                }
                RadGrid1.DataSource = dt2;
                Session["AssetList"] = dt2;
            }
            finally
            {
                ObjDBHelp.CloseConnection(SqlConn);
                dt2 = null;
            }

Thanks,
Mohamed .

4 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 May 2011, 06:58 AM
Hello Mohamed,

The following forum thread discusses the same scenario. Check the thread for more details.
Clearing Grid ItemsCollection.

Thanks,
Princy.
0
mohamed
Top achievements
Rank 1
answered on 10 May 2011, 07:04 AM
thanks for ur reply.

where i call this
every where i call this value error come .
RadGrid1.DataSource = New String() {}

Thanks,
Mohamed.
0
Princy
Top achievements
Rank 2
answered on 10 May 2011, 07:57 AM
Hello Mohamed,

Sorry, the code in the thread was VB version. Try the following code.

C#:
this.RadGrid1.DataSource = new string[0];

Thanks,
Princy.
0
mohamed
Top achievements
Rank 1
answered on 10 May 2011, 08:25 AM
Thanks for ur reply princy,

nothing change .

i called this on needdata source

else
                {                    
                    this.RadGrid1.DataSource = new string[0];                    
                    string selectQuery = "SELECT AssetName, SerialNumber, Asset_UserID,Asset_Inactive FROM [Assets] where Asset_Inactive>0 order by AssetName asc";
                    sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                    sqladp.Fill(dt1);
                    int i = dt1.Rows.Count;
                    dt1 = null;


                    if (i > 0)
                    {
                        selectQuery = "select  a.AssetID,a.AssetName,a.SerialNumber,a.Asset_UserID,b.ppl_Name,a.Asset_Inactive FROM [Assets] a , People b  " +
                                            "where a.Asset_UserID=b.PeopleID and a.Asset_Inactive=1 order by AssetName asc";
                        sqladp.SelectCommand = new SqlCommand(selectQuery, SqlConn);
                        sqladp.Fill(dt2);
                        showinactive = "0";
                    }
                }
                RadGrid1.DataSource = dt2;
                Session["AssetList"] = dt2;

Thanks,
Mohamed.
Tags
Grid
Asked by
mohamed
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
mohamed
Top achievements
Rank 1
Share this question
or