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

RadGrid not refreshing after an ASP.NET control posts back

1 Answer 66 Views
Grid
This is a migrated thread and some comments may be shown as answers.
DAVE
Top achievements
Rank 1
DAVE asked on 09 Sep 2013, 03:50 AM
I am doing simple data binding with a Grid.  That part works fine.  I also have a dropdownlist control where the user can select different time periods for the query the supplies the grid.  When the user changes a selection in the dropdownlist, the control is posting back but the grid never updates.  I can't quite tell what the problem is.  What should I be looking for?

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 09 Sep 2013, 04:47 AM
Hi,

Please take a look into the following code snippet I tried to bind RadGrid with data depending upon the selection of the RadDropDownList.

ASPX:
<telerik:RadDropDownList ID="RadDropDownList1" runat="server" AutoPostBack="true"
    OnSelectedIndexChanged="RadDropDownList1_SelectedIndexChanged">
    <Items>
        <telerik:DropDownListItem Text="1" />
        <telerik:DropDownListItem Text="2" />
    </Items>
</telerik:RadDropDownList>
<telerik:RadGrid ID="Radgrid1" runat="server" OnNeedDataSource="Radgrid1_NeedDataSource">
</telerik:RadGrid>

C#:
public static string connection = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
public SqlCommand SqlCommand = new SqlCommand();
DataTable dt1 = new DataTable();
string selectQuery1=string.Empty;
public static string bind = string.Empty;
protected void Radgrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    string query = string.Empty;
    if (bind == "Employees")
    {
          
        selectQuery1 = "SELECT  * FROM [Employees]";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        Radgrid1.DataSource = dt1;
    }
    else if(bind == "Orders")
    {
        selectQuery1 = "SELECT  * FROM [Orders]";
        SqlDataAdapter adapter2 = new SqlDataAdapter(selectQuery1, conn);
        conn.Open();
        adapter2.Fill(dt1);
        conn.Close();
        Radgrid1.DataSource = dt1;
    }
}
protected void RadDropDownList1_SelectedIndexChanged(object sender, Telerik.Web.UI.DropDownListEventArgs e)
{
    RadDropDownList ddl = (RadDropDownList)sender;
    if (ddl.SelectedText == "1")
    {
        bind = "Orders";
        Radgrid1.Rebind();
    }
    else
    {
        bind = "Employees";
        Radgrid1.Rebind();
    }
}

Please provide your code if it doesn't help.

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