Click here to Skip to main content
15,885,877 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
i have 1 gridview at my page i want that if i will click on any row of gridview than it should open another page how it can possible?should i do work on the row command event?tell me please
i want that after clicking on any row of gridview at runtime it should redirect to the another page with id because the id will be redirect withit and that page will get that id. and some data will come according to that id on that page.plz tell me how it can be possible?
Posted
Updated 2-Dec-11 18:52pm
v3
Comments
Smithers-Jones 2-Dec-11 6:07am    
Do not use textspeak, that is unprofessional and childish. You have a full keyboard, so use it.
Member 8387468 2-Dec-11 6:15am    
OK

1 solution

You completly three solution to your problem:
You can either use the following template feild with hyperlink feild in it.
XML
<asp:TemplateField>
    <ItemTemplate>
        <asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl ='<%# Bind("EmpCode") %>'>GoTo Next Page</asp:HyperLink>
    </ItemTemplate>

Or You can HyperLinkField of gridview
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="Url link database"
        DataTextField="Url Title Feid in database" />
        <asp:ButtonField ButtonType ="Link" CommandName ="NaviagetonextPage" />

or you can button field of grid view with on row command event:
<asp:ButtonField ButtonType ="Link" CommandName ="NaviagetonextPage" />

C#
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
   {
       if (e.CommandName == "NaviagetonextPage")
       {
           NaviagetonextPage();
       }
   }
   public void NaviagetonextPage()
   {

   }
 
Share this answer
 
Comments
Member 8387468 2-Dec-11 7:45am    
i am using this code but when i am redirecting it on another page it should be redirecting with the id.for example:-
Response.Redirect("Contactfollowup.aspx?id="+id);
and this id is got by another page..so how it can possible?
Member 8387468 3-Dec-11 0:45am    
plz reply sir
Tarun Mangukiya 3-Dec-11 1:10am    
do you want to get the id of the row you have selected?
Member 8387468 3-Dec-11 1:36am    
yes.actly when i m using gridview then there is no control that is binded by the id.and its mendatory for me to get id.for example there are so many records are showing in my gridview and i want that after clicking on any row that should redirect to another page with an id sothat at another page i can get the data regarding that record...
Member 8387468 3-Dec-11 1:54am    
<script runat="server">

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
System.Data.DataRowView drv = e.Row.DataItem as System.Data.DataRowView;
e.Row.Attributes.Add("ondblclick", String.Format("window.location='foo.aspx?subject={0}'", drv["Subject"]));
}
}
</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:testConnectionString %>"
SelectCommand="SELECT [Subject], [EndTime], [StartTime] FROM [DateTest]">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnRowDataBound="GridView1_RowDataBound">
<columns>
<asp:BoundField DataField="Subject" HeaderText="Subject" SortExpression="Subject" />
<asp:BoundField DataField="StartTime" HeaderText="StartTime" SortExpression="StartTime" />
<asp:BoundField DataField="EndTime" HeaderText="EndTime" SortExpression="EndTime" />


</div>
</form>
</body>
</html>
but here subject is null so its showing object instance null exception

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