Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to redirect from one page to another page after clicking on the row of gridview with id.means after clicking any cell of gridview it should be redirected to another page with the id.so that by that id i can get the information on another page..and after binding that when i will move cursor on gridview it should indicate that if i will click on it than it will redirect to another page for example hand symbol(cursor).how it can possible please tell me actually i am new so tell me
Posted

Allow AutoGenerateSelectButton=true;
on RowCommand Event
C#
protected void fect_taskid(object sender, GridViewCommandEventArgs e)
    {
       
            
                int index = Convert.ToInt32(e.CommandArgument);
                GridViewRow row = GridView1.Rows[index]; 
                  Session["id"]=row.Cells[1].Text;// 1 is index for your id
                  Response.Redirect("yourpage.aspx");
      }

Hope it helps.
 
Share this answer
 
Comments
Member 8387468 7-Dec-11 2:33am    
at run time after clicking on rows its not working
Member 8387468 7-Dec-11 5:01am    
why don't you reply
Try
C#
protected void Redirect(object sender, EventArgs e)
{
    Server.Transfer("~/yourpages.aspx");
}


and then call a server side method on click event for Redirect which using Server.Transfer to redirect.
Reference Link :- http://www.aspsnippets.com/Articles/Pass-ASP.Net-GridView-from-one-page-to-another-page.aspx[^]
and
or try given code
C#
protected void DGridview_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            
            int selectedIndex = int.Parse(e.CommandArgument.ToString());
            string commandName = e.CommandName;
            this.DGridview.SelectedIndex = selectedIndex;
         
        }
 
Share this answer
 
Comments
Member 8387468 7-Dec-11 4:55am    
how it can possible sir? i want to redirect according to id.because on next page i am getting that id by using Query string and retrieving data according to that id.so i have to redirect with the id.
Member 8387468 7-Dec-11 4:55am    
tell me plz as soon as possible plz
Check this link, serves the same purpose which you are looking for:
link-button-using-in-gridview-another-page-redirect[^]
 
Share this answer
 
Add a label to your gridview's column as itemtemplate. Set its text to the ID and keep this label invisible. Now on RowDataBound event of your gridview write:

C#
protected void YourGridView_RowDataBound(object sender, GridViewRowEventArgs e) {    
if(e.Row.RowType == DataControlRowType.DataRow)   
{   
Label lbl = (Label)e.Row.FindControl("yourLabelsID
string ID = lbl.Text.Trim();
e.Row.Attributes.Add("onclick","top.location.href='YourRedirectPage.aspx?id=" + ID + "';"); 
}   
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900