Arnold Layne
asked on
dynamically changing the datasource in codebehind file
I am using asp.net and C#. I am familiar with gridviews and datasources. However, i cannot figure out a way, using these controls, to dynamically filter results in the code behind from the sqldatasourse I have set up.
So if the query string has user="all", i want it populate the data grid with all records. If user equals a certain name, it will only show records associated wit the user.
I thought about making multiple datasources and swapping them in and out based on what comes in from the query string, but it doesn't work. The table I am getting data from is simple. It has two columns, filename and user. I want the data grid to only show the filename field, and only show what is dictated by the user found in the query string.
Also, very important. I need to wrap every result line in a hyperlink, that will use the filename data to build the final part of the url of the link
So if the query string has user="all", i want it populate the data grid with all records. If user equals a certain name, it will only show records associated wit the user.
I thought about making multiple datasources and swapping them in and out based on what comes in from the query string, but it doesn't work. The table I am getting data from is simple. It has two columns, filename and user. I want the data grid to only show the filename field, and only show what is dictated by the user found in the query string.
Also, very important. I need to wrap every result line in a hyperlink, that will use the filename data to build the final part of the url of the link
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
In your RowDataBound event, you can do something like this;
if (e.Row.RowType == DataControlRowType.DataRow ) {
HyperLink myLink = new HyperLink();
myLink.Text = columnText;
myLink.NavigateUrl = "Update.aspx?id=" + columnID;
container.Controls.Add(myL ink);
}
Where columnText is the result that you would like to display in the link and columnID is the key value that you need to navigate in the URL.
if (e.Row.RowType == DataControlRowType.DataRow
HyperLink myLink = new HyperLink();
myLink.Text = columnText;
myLink.NavigateUrl = "Update.aspx?id=" + columnID;
container.Controls.Add(myL
}
Where columnText is the result that you would like to display in the link and columnID is the key value that you need to navigate in the URL.
ASKER
I finally saw what you meant when creating the datasouce inside VS. There was an option for parameters and it worked. Looks like ot grabs the value after the query string and sets up a variable to do things with for you.
Awesome! Glad you were able to get things working.
ASKER