Set Gridview DataNavigateUrlFormatString Dynamically Inside User Control (ASCX)

I have a problem, I do not know if this can be done.

I have an aspx page that loads a selection onto user activity of a user control (ascx).

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

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

I want that when clicking this hyperlink it directs the parameters to the same page, but I can not do it correctly. for some reason I tried this:

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

but on the page, the link refers to% page% as a string. can someone pls direct me like that.

ps it worked when it was like that and ascx was in the root folder of the solution, the problem started when I moved all my controls to a folder in the root called "Controls"

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

early.

+3
source share
1 answer

Use the template field and add a 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> 

Or you can use the GridView_RowDatabound event handler and change the Navigateurl for a specific 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(); } } 

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

+8
source

Source: https://habr.com/ru/post/916650/


All Articles