Reputation: 144
I am working on asp.net gridview (WEB.UI.Contorl). I want to use one gridview only. When a button is clicked, gridview1 should be filled by table1. When second button is clicked, gridview1 should be filled by table2.
Is this possible..?
Upvotes: 1
Views: 181
Reputation: 2378
Have you tried this
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Button 1" />
<asp:Button ID="Button2" runat="server" onclick="Button2_Click"
Text="Button 2" />
<br />
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
in code behind
protected void Button1_Click(object sender, EventArgs e)
{
GridView1.DataSource = CallToMethodThatReturnFirstDatatable();
GridView1.DataBind();
}
protected void Button2_Click(object sender, EventArgs e)
{
GridView1.DataSource = CallToMethodThatReturnSecondDatatable();
GridView1.DataBind();
}
Upvotes: 1
Reputation: 1724
Yes call a stored procedure: MyProc(@ParamTable, ....) Then in the proc have if statements to choose the table depending on the value of @Param. However this is not a good approach for a number of reasons: Linq will not produce your classes unless you do far more jigery pokery. good learning curve though... As you are using asp net, it is probable you are generating a postback to get the other table, so a respose redirect to another page will have absolutely no overhead to speak of. If you insist on doing it async without a postback then you'll need to make the procedure do something like an insert into a table variable then union the select on the table variable variable with a hard coded row of column variables which are somehow excluded and not returned...
Upvotes: 0