Click here to Skip to main content
15,889,843 members
Please Sign up or sign in to vote.
5.00/5 (2 votes)
Dear all,

I would like to be able to know, how can i click on gridview name column's rows (name= storm) and it would direct me to another page, with label stating "you are now seeing storm details"

ASP.NET
<asp:GridView ID="GridView1" runat="server" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" onrowdatabound="gvrecords_RowDataBound"
        AllowSorting="True" OnSorting="ComponentGridView_Sorting" BackColor="White" 
        BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="5">
        <FooterStyle BackColor="White" ForeColor="#000066" />
        <HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
        <PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
        <RowStyle ForeColor="#000066" />
        <SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
        <SortedAscendingCellStyle BackColor="#F1F1F1" />
        <SortedAscendingHeaderStyle BackColor="#007DBB" />
        <SortedDescendingCellStyle BackColor="#CAC9C9" />
        <SortedDescendingHeaderStyle BackColor="#00547E" />
        
    </asp:GridView>


The gridview is binded to the database from code behind. if required, i am happy to post the code.
Any suggestion how can i carry out this functionality. Many thanks for your help.
Posted

Easiest way would be Setting NavigateUrl property of HyperLink in TemplateField in Markup of the Gridview

Refer below link for doing this multiple ways

pass-querystring-parameter-with-navigaterurl-in-hyperlink-inside-a-gridview.aspx[^]
 
Share this answer
 
YOu can create a template field in Gridview and bind it with your required column like below.

XML
<asp:TemplateField  HeaderText="View" ItemStyle-Width="100px" ItemStyle-CssClass="grid_row_style" ItemStyle-HorizontalAlign="Left">
     <ItemTemplate>
     <asp:LinkButton ID="LinkButton1" CommandName="somecommandname" runat="server">
         <a class="data_grd_link"   href=javascript:GotoPage('<%# DataBinder.Eval(Container.DataItem,"NAME")%>')>
          <img border="0" src="../img/img.png"/></a>
     </asp:LinkButton>
     </ItemTemplate>

    </asp:TemplateField>



and to open it in new page use the following javascript function which would get your parameter from the above template field and open a new page with that parameter as querstring.


C#
function GotoPage(NamePassing) {
            var page = "../FolderName/PageName.aspx?name=" + NamePassing;
            var windowprops = "width=95%,height=150,location=yes,toolbar=no,menubar=no,scrollbars=yes,resizable=yes";
            window.open(page, "", "height=700,width=1000,scrollbars,resizable=no");
        }



I hope it will help. :)
 
Share this answer
 
v2

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