Data Grid filtering
-
I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT
-
I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT
If you want to disply only a particular user's items only in the datagrid, you will have to create a different datasource for that. For example, if you are using dataset or datatable as datasource, you will have to create a dataview and filter the particular user id. Then bind the datagrid with the dataview as datasource hope this will help
-
I have a data grid in ASP.NET 2.0 that contains the following fields: ID Task Comments User The User field is populated with the login name of the user who created the item. How can I filter this dataset with a Page_Load event based upon the users login name? GT
Hi, Firstly You must have a dataset on your hand code behind. You can write a method like this, protected void Page_Load(object sender, EventArgs e) { if{!IsPostBack} { querystring = "Your query"; GetData(String queryString); yourdatagrid.DataBind; } } DataSet GetData(String queryString) { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(queryString, SqlConnection); adapter.Fill(ds); return ds; } I hope I understand you correctly.
-
Hi, Firstly You must have a dataset on your hand code behind. You can write a method like this, protected void Page_Load(object sender, EventArgs e) { if{!IsPostBack} { querystring = "Your query"; GetData(String queryString); yourdatagrid.DataBind; } } DataSet GetData(String queryString) { DataSet ds = new DataSet(); SqlDataAdapter adapter = new SqlDataAdapter(queryString, SqlConnection); adapter.Fill(ds); return ds; } I hope I understand you correctly.
-
Well let me see if I can explain a little better. I want to somehow take the current users login name and filter a table with that string. GT
-
Well let me see if I can explain a little better. I want to somehow take the current users login name and filter a table with that string. GT
The grids expose a RowFilter property, which can be set to something like
myGrid.RowFilter = "UserName=" + userNameToFilterBy;
myGrid.DataBind();"Now I guess I'll sit back and watch people misinterpret what I just said......" Christian Graus At The Soapbox