I am trying to pass searching text and based on the text entered into the textbox I want to fetch data from the database and display into gridview. I have a gridview which consists of Country name, Company Name, Product Category. Currently I am using a Textbox in which I am entering Company name and Holding this data into a session variable and passing this session variable as a where clause with the select query to display into gridview. I want that If I enter Country name and Product name in the same textbox then also the gridview data should display. How can I do this by using a single textbox? My aspx page-
<table>
<tr>
<td><asp:TextBox ID="TextBox1" runat="server" Width="167px"></asp:TextBox></td>
</tr>
<tr>
<td><asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Submit"
Width="116px" /></td>
</tr>
<tr>
<asp:GridView ID="GridView1" runat="server">
</asp:GridView>
</tr>
</table>
My cs Page-
public void bind()
{
dt = g1.return_dt("select * from tbl1 where id is not null " + Session["Name"] + " order by compname ");
if (dt.Rows.Count > 0)
{
adsource = new PagedDataSource();
adsource.DataSource = dt.DefaultView;
adsource.PageSize = 10;
adsource.AllowPaging = true;
adsource.CurrentPageIndex = pos;
btnfirst.Enabled = !adsource.IsFirstPage;
btnprevious.Enabled = !adsource.IsFirstPage;
btnlast.Enabled = !adsource.IsLastPage;
btnnext.Enabled = !adsource.IsLastPage;
GridView1.DataSource = adsource;
GridView1.DataBind();
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
Session["Name"] = "and compname like '%" + TextBox1.Text + "%'";
}
else
{
Session["Name"] = null;
}
}
I want to know How can I use this Session["Name"] object to pass Product Category and Country Name along with the Company Name. i.e. I want to know How can I display data in my gridview based on the different condition passed from this textbox. Please guide me.