Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi , i have a dropdownlist ,txtbox and a gridview.The dynamic data's are binded to it.I want to add a static value to the dropdownlist like "select" so that if i click on that select i should get all the values in gridview.i.e.,even if the textbox is empty and dropdownlist==select the gridview values must be displayed.

The functionality is :
1.wen values are entered in textbox the gridview is binded according to it and also the ddl will b displayed according to the textbox value
2.ddl will also work according to it.and ddl maintains the same value after postback.

But currently my problem is if i click on the "select option" in ddl nothin gets displayed in the gridview .but i want gridview values to be displayed for ddl="select"(static value).

how to bind the static value to the gridview ?ur answers are welcomed..
Posted
Comments
DamithSL 10-Jul-15 1:54am    
update the question with your code and tag the question with application type like asp.net, winform etc..
[no name] 10-Jul-15 2:00am    
public void txtfullname_TextChanged(object sender, EventArgs e)
{
DataView dvtxtfullname = new DataView((DataTable)Session["GrdSearch"]);
StringBuilder filter = new StringBuilder();
filter.Append("fullname like '%" + Convert.ToString(txtfullname.Text) + "%'");
dvtxtfullname.RowFilter = filter.ToString();
ddlCountries.DataSource = dvtxtfullname.ToTable(true, "Country");
ddlCountries.DataTextField = "Country";
ddlCountries.DataBind();
ddlCountries.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select country", ""));

DataView dvgrid = new DataView((DataTable)Session["GrdSearch"]);

if (!string.IsNullOrEmpty(ddlCountries.SelectedValue))
{
filter.Append(" Country='" + Convert.ToString(ddlCountries.SelectedItem) + "'");

}

dvgrid.RowFilter = filter.ToString();
grdSearch.DataSource = dvgrid;
grdSearch.DataBind();

if (Session["ddlvalue"] != null)
{
ddlCountries.SelectedValue = Session["ddlvalue"].ToString();
dvtxtfullname.RowFilter = "Country='" + ddlCountries.SelectedItem + "' AND fullname like '%" + Convert.ToString(txtfullname.Text) + "%'";
grdSearch.DataSource = dvtxtfullname;
grdSearch.DataBind();
}

}

protected void ddlCountries_SelectedIndexChanged(object sender, EventArgs e)
{
DataTable dtCountries = (DataTable)Session["GrdSearch"];
DataView dv = new DataView(dtCountries);
dv.RowFilter = "Country='" + ddlCountries.SelectedItem + "' AND fullname like '%" + Convert.ToString(txtfullname.Text) + "%'";
grdSearch.DataSource = dv;
grdSearch.DataBind();
//ddlCountries.Items.Insert(0, new System.Web.UI.WebControls.ListItem("Select country", ""));

Session["ddlvalue"] = ddlCountries.SelectedValue;

}
[no name] 10-Jul-15 2:27am    
pls do help.....ur replies are welcomed

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900