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

Grid View

2 Answers 94 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Angella
Top achievements
Rank 1
Angella asked on 16 Apr 2012, 05:04 AM
Hi all,
I need two grid view in my page.I have to show both details on different link button click, now I could show only one grid and its showing in the Page load itself. Please help me with ideas.
Thanks.

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 16 Apr 2012, 06:42 AM
Hi Angella,

Here is the sample code I tried to bind RadGrid on different LinkButton Click. Please take a look into the following code.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="true"  Visible="false"
        onneeddatasource="RadGrid1_NeedDataSource"></telerik:RadGrid>
    <asp:LinkButton ID="LinkButton1" runat="server" onclick="LinkButton1_Click" Text="Orders"></asp:LinkButton>
    <asp:LinkButton ID="LinkButton2" runat="server"
    onclick="LinkButton2_Click" Text="Employee"></asp:LinkButton>

C#:
string Bind = string.Empty;
public static string connection = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString3"].ConnectionString;
SqlConnection conn = new SqlConnection(connection);
public SqlCommand SqlCommand = new SqlCommand();
protected void RadGrid1_NeedDataSource(object sender, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
{
    if (Bind == "Orders")
    {
        string selectQuery1 = "select top 10 OrderID,CustomerID from Orders";
        SqlDataAdapter adapter1 = new SqlDataAdapter(selectQuery1, conn);
        DataTable dt1 = new DataTable();
        conn.Open();
        adapter1.Fill(dt1);
        conn.Close();
        RadGrid1.DataSource = dt1;
    }
 
    if (Bind == "Employee")
    {
 
        string selectQuery2 = "select top 10 EmployeeID,LastName from Employees";
        SqlDataAdapter adapter2 = new SqlDataAdapter(selectQuery2, conn);
        DataTable dt2 = new DataTable();
        conn.Open();
        adapter2.Fill(dt2);
        conn.Close();
        RadGrid1.DataSource = dt2;
    }
}
protected void LinkButton1_Click(object sender, EventArgs e)
{
    Bind = "Orders";
    RadGrid1.Visible = true;
    RadGrid1.Rebind();
}
protected void LinkButton2_Click(object sender, EventArgs e)
{
    Bind = "Employee";
    RadGrid1.Visible = true;
    RadGrid1.Rebind();
}

Please elaborate your scenario if it doesn't help.
Thanks,
Shinu. 
0
Angella
Top achievements
Rank 1
answered on 17 Apr 2012, 07:56 AM
Thanks Shinu.
Tags
Grid
Asked by
Angella
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Angella
Top achievements
Rank 1
Share this question
or