hi everyone
i want to ask u people could anyone help me how can i display the data in the datagrid column as hyperlink so that when i click on dat cell that will redirect me to the specified page.......
hope i have well explained my question thanx in advance.....
bye
I had to do something like this once before, and I used the viewstate in order to do it. We had a datagrid that would output unknown columns based on user queries. Here is the solution I found:
- protected void grdResults_RowDataBound(object sender, GridViewRowEventArgs e)
-
{
-
// Go through the header row and if the column header is
-
// the flagged header I'm looking for, mark the viewstate
-
if (e.Row.RowType.ToString().Equals("Header"))
-
{
-
for (int i = 0; i < e.Row.Cells.Count; i++)
-
{
-
DataControlFieldCell tc = (DataControlFieldCell)e.Row.Cells[i];
-
if (tc.ContainingField.HeaderText.Equals(flaggedHeader))
-
{
-
ViewState.Add("hypercolumn", i);
-
}
-
}
-
}
-
// Go through the rest of the rows in the datagrid, if there is a viewstate
-
// marked, set the hyperlink
-
else
-
{
-
for (int i = 0; i < e.Row.Cells.Count; i++)
-
{
-
if (ViewState["hypercolumn"] != null)
-
{
-
if (i == (int)ViewState["hypercolumn"])
-
{
-
HyperLink h = new HyperLink();
-
h.Text = e.Row.Cells[i].Text;
-
h.NavigateUrl = myURL;
-
-
// Setting Target to _blank causes it to open a new
-
// window when clicking on the hyperlink. Not setting
-
// this property means that clicking on the hyperlink will
-
// redirect the current window
-
h.Target = "_blank";
-
e.Row.Cells[i].Controls.Add(h);
-
}
-
}
-
}
-
}
-
}
If the columns are defined in the code behind, then all you need is to make the column hyperlink, set the NavigateUrl and the Target.
Also, if you end up messing with the viewstate the way I did, remember to reset the viewstate.