Reputation: 1088
In Asp.net C#
.I have a gridview
control.
col1 - A - B - C
What I want that when I click on A
then I should redirect to second page where
i will perform a query and supply 'A'
as parameter in query and retrieve values
from database on the basis of 'A'
For ex:
string query="select * from table1 where name='A'";
Q1.Is there any other way or control other than gridview
which i can use in this situation.
Q2.If i use Gridview
then how i can get value, save it in some field and then supplly it on next page and use it in query.
I have found things like templatefields
,linkbutton
,hyperlink
but they do not seem to resolve my problem.
Upvotes: 0
Views: 1755
Reputation: 1088
I found it useful to move this answer from comments, so this this can be helpful for others.
on gridview_rowDataBound
event write this code
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor='#ceedfc'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=''");
e.Row.Attributes.Add("style", "cursor:pointer;");
e.Row.Attributes.Add("onclick", "location='WebForm3.aspx?id=" + e.Row.Cells[0].Text + "'");
}
then on next page get value of id by
Id = Request.QueryString["ID"].ToString();
Upvotes: 1
Reputation: 50728
The very simplistic way is make A a HyperLinkField which navigates to the second page and passes the querystring. You can do what you say with javascript by attaching to the table cell click event, and then on click, grab the cell's contents via cell.innerHTML and pass that to the second page, passing the value via the querystring. The very simplistic way is use a link. Add to your grid:
<asp:HyperLinkColumn DataNavigateUrlFormatString="SecondPage?value={0}"
DataNavigateUrlFields="ColumnNameOfWhateverAIs"
DataTextField="ColumnNameOfWhateverAIs" />
Upvotes: 0