设置用户控件中的GridView DataNavigateUrlFormatString动态(ASCX) [英] Set Gridview DataNavigateUrlFormatString Dynamically inside User Control(ASCX)

查看:147
本文介绍了设置用户控件中的GridView DataNavigateUrlFormatString动态(ASCX)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个不知道的问题,如果可以做到的。

i have a issue that i dont know if it can be done.

我有一个在aspx页面,
上用户活动的负载dedpends用户控件(ASCX)。

i have an in an aspx page , that loads dedpends on user activity a user control (ascx).

在用户控件有一个GridView其中我列之一的超链接。

the user control has a gridview which one of my columns are hyperlink.

<asp:HyperLinkField  DataNavigateUrlFormatString='<%page %>'
        DataTextField="ReqId" HeaderText="Request No." DataNavigateUrlFields="ReqId" />

我想,在该超链接的点击,它会指向同一个页面的参数,
但我不能这样做的权利。由于某种原因,所以我尝试这一个:

i want that on click of that hyperlink , it will direct to the same page with parameters, but i cant do it right. for some reason so i tried this one:

<%string page = Page.Request.Path + "reqid={0}"; %>

但在页面中链接指向%页%为字符串。
可有人请告诉我如何把它。

but in the page the link refers to %page% as a string . can someone pls direct me how to it.

P.S
它曾经工作的时候是这样的,在ASCX在解决方案的根文件夹,这个问题开始,当我在一个名为根动了我的所有控件到文件夹控件

p.s it used to work when it was like that and the ascx was in root folder of the solution, the problem start when i moved all my controls to a folder in the root named "Controls"

<asp:HyperLinkField  DataNavigateUrlFormatString="?reqid={0}"
        DataTextField="ReqId" HeaderText="מספר בקשה" DataNavigateUrlFields="ReqId" />

先谢谢了。

推荐答案

使用一个模板字段并添加超链接到它。

Use a template field and add hyperlink to it.

<asp:TemplateField HeaderText="Request No.">
   <ItemTemplate>
     <asp:HyperLink ID="EditHyperLink1" runat="server" 
          NavigateUrl='<%# Page.Request.Path + "?reqid=" + Eval("ReqId") %>'
          Text='<%# Eval("ReqId") %>' >
     </asp:HyperLink>
   </ItemTemplate>
</asp:TemplateField>

或者你可以使用GridView_RowDatabound事件处理程序,并更改Navigateurl用于特定控制。

Or you can use GridView_RowDatabound event handler and change the Navigateurl for the particular control.

protected void myGV_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        HyperLink myHL = (HyperLink)e.Row.FindControl("EditHyperLink1");
        myHL.NavigateUrl = Page.Request.Path + "?reqid=" + e.Row.Cells[0].Text.ToString();
    }
}

我假设REQID是第一个单元格present。

I have assumed that ReqId is present in 1st cell.

这篇关于设置用户控件中的GridView DataNavigateUrlFormatString动态(ASCX)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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