Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LinkButton In Gridview

Status
Not open for further replies.

Waynest

Programmer
Jun 22, 2000
321
GB
Hello mates

I have a linkbutton column in a gridview. It shows order numbers & I want to go to another page showing the order lines when one of the order number links is clicked

Ive used the following code but the value of Cells[0] is always blank. I think this would work if it were a normal cell but not here because its a button. I need to reference it a different way?


protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{
int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView1.Rows[index];
TableCell OrderNo = selectedRow.Cells[0];
Session["OrderNo"] = OrderNo.Text;
Response.Redirect("my other page");

}
 
Heres how for anyone else, thanks for reading

int index = Convert.ToInt32(e.CommandArgument);
GridViewRow selectedRow = GridView1.Rows[index];
TableCell OrderNo = selectedRow.Cells[0];
Session["OrderNo"] = ((LinkButton)selectedRow.Cells[0].Controls[0]).Text;
Response.Redirect("~");
 
Why are you using a LinkButton? It seems a rather convoluted way to have to go back to the server just to redirect the user.

I'd use a HyperLinkField and set the values there which will redirect the user without the postback e.g.
Code:
<asp:HyperLinkField DataNavigateUrlFormatString="~\OtherPage.aspx?Id={0}" DataNavigateUrlFields="Id" Text="View Order Lines" />




-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top