如何将查询从gridview传递到另一个页面 [英] How to pass query from gridview to another page

查看:82
本文介绍了如何将查询从gridview传递到另一个页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,



我想知道,如何点击gridview name列的行(name = storm)它会指示我到另一页,标签上写着你现在看到暴风雨的细节



 < ;   asp:GridView     ID   =  GridView1    runat   =  server    

onselectedindexchanged < span class =code-keyword> = GridView1_SelectedIndexChanged onrowdatabound = gvrecords_RowDataBound

AllowSorting = True OnSortin g = ComponentGridView_Sorting BackColor = 白色

BorderColor = #CCCCCC BorderStyle = BorderWidth = 1px CellPadding = 5 >
< FooterStyle BackColor = 白色 ForeColor < span class =code-keyword> = #000066 / >
< HeaderStyle BackColor = #006699 字体粗体 = ForeColor = 白色 / >
< PagerStyle BackColor = 白色 ForeColor = #000066 Horizo​​ntalAlign = / >
< RowStyle ForeColor = #000066 / >
< SelectedRowStyle BackColor = #669999 Font-Bold = True ForeColor = 白色 / >
< SortedAscendingCellStyle BackColor = #F1F1F1 / >
< SortedAscendingHeaderStyle BackColor = #007DBB / >
< < span class =code-leadattribute> SortedDescendingCellStyle BackColor = #CAC9C9 / >
< SortedDescendingHeaderStyle BackColor = #00547E / >

< / asp: GridView >





gridview从代码隐藏到数据库。如果需要,我很乐意发布代码。

任何建议如何执行此功能。非常感谢您的帮助。

解决方案

最简单的方法是在Gridview标记中的TemplateField中设置HyperLink的NavigateUrl属性



请参阅以下链接以多种方式执行此操作



传递查询字符串参数与 - navigaterurl功能于超级链接-内部-A-gridview.aspx [ ^ ]


你可以在Gridview中创建一个模板字段,并将其与你所需的列绑定,如下所示。



 <   asp:TemplateField       HeaderText   = 查看    ItemStyle-Width   =  100px    ItemStyle-CssClass   =  grid_row_style    ItemStyle-Horizo​​ntalAlign   =  >  
< ItemTemplate >
< asp:LinkBut​​ton < span class =code-attribute> ID = LinkBut​​ton1 CommandName = somecommandname runat = 服务器 >
< a class = data_grd_link href = javascript:GotoPage(' <%# DataBinder.Eval(Container.DataItem,NAME)% > ; ')>
< img < span class =code-attribute> border
= 0 src = ../ img / img.png / > < / a >
< / asp:LinkBut​​ton >
< / ItemTemplate >

< / asp:TemplateField >







并打开它新页面使用以下javascript函数,该函数将从上面的模板字段中获取您的参数并打开一个带有该参数的新页面作为querstring。





 function GotoPage(NamePassing){
var page = ../ FolderName / PageName.aspx?name = + NamePassing;
var windowprops = width = 95% ,高度= 150,位置=是,工具栏=没有,菜单栏=没有,滚动条=是,可调整大小=是;
window.open(页面, height = 700,width = 1000,滚动条,resizable = no);
}







我希望它会有所帮助。 :)


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: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.

解决方案

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[^]


YOu can create a template field in Gridview and bind it with your required column like below.

<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.


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. :)


这篇关于如何将查询从gridview传递到另一个页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆