hyperlink in a item template inside the gridview - asp.net

I have this hyperlink in a item template inside the gridview
<asp:TemplateField Headertext ="SN0">
<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%# DataBinder.Eval(Container.DataItem,"Container.DataItemIndex + 1")%>'
NavigateUrl='<%# "ResolveComplaint.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ComplaintProfileId").tostring & _
"&Status=" & DataBinder.Eval(Container.DataItem,"Status").tostusring %>' ID="Hyperlink2"/>
</ItemTemplate>
</asp:TemplateField>
Basically, I am trying to make the first column(SN0) in a gridview. On click on the hyperlink, it redirects to another Page. I am carrying ComplaintProfileId, Status fields
to the next page
This gives me a compiletime error:
Compiler Error Message: CS1026: ) expected
Thanks
Sun

The problem is when you are trying to set the NavigateUrl property. You are using the & for concatenation, but you have to use the + sign for that. e.g.
NavigateUrl='<%# "ResolveComplaint.aspx?Name=" + DataBinder.Eval (Container.DataItem,"ComplaintProfileId").tostring +
"&Status=" + DataBinder.Eval(Container.DataItem,"Status").tostusring %>'

Should your .tostring and tostusring calls be .ToString()?

Related

The server tag is not well formed in gridview

I have the hyperlink control on the GridView and I want to call the javascript function with passing parameters. I am getting Server Tag is not well formed error. I tried changing double quotes to single quote etc, still the same issue.
Can anyone help me find the issue here .
Line 1946: <asp:TemplateField HeaderText="Transaction Id">
Line 1947: <ItemTemplate>
Line 1948: <asp:HyperLink ID="lbltransId"
runat="server"
Text="<%# "<a href=\"javascript:subViewBookingDetails('"+
Eval("transId") +
"','','','','',,'','','')\">" +
Eval("transId") + "</a>" %>"></asp:HyperLink>
Line 1949: </ItemTemplate>
Line 1950: <FooterTemplate>
This should work. Do not use Text to populate link inside, use NavigateUrl instead.
<asp:HyperLink id="hyperlink1"
NavigateUrl="<%# String.Format(
"javascript:subViewBookingDetails({0} ,,,,,,,,)", Eval("transId"))%>"
Text="<%#Eval("transId") %>"
runat="server"/>
Text='<%# "" + Eval("transId") + "" %>'

How to handle single quote in query string parameter values inside Eval for navigateurl property of hyperlink

Inside Gridview control
If my ID_Logon value has single quote characters in it, then the string gets terminated at the single quote.
for eg, if Id_Logon = O'connel
then only the O is being passed as a parameter. How to pass the whole string?
<asp:TemplateField HeaderText="LogonID" >
<ItemTemplate>
<asp:HyperLink ID="hyperlink1"
NavigateUrl='<%#"EditLogon.aspx?ID=" + Eval("ID_Logon")%>'
Text='<%# Bind("ID_Logon")%>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Try this
NavigateUrl='http://home/?<%# Eval("U_ID") %>'
or
NavigateUrl='<%# "http://home/?" + (string)Eval("U_ID") %>'
source asp:hyperLink NavigateURL and Eval functions

Navigate URL for Hyperlink is changeed, when the Title set to hyperlink has "/" inbetween?

I am using hyperlinks inside datalist and the datalist is binded with a datatable
Hyperlink inside my datalist :
<asp:HyperLink ID="hypSubSections" runat="server" NavigateUrl='<%# DataBinder.Eval(Container.DataItem,"Pagename") + "?ID=" + DataBinder.Eval(Container.DataItem,"ID") + "&Code=" + DataBinder.Eval(Container.DataItem,"CODE") + "&Title=" + DataBinder.Eval(Container.DataItem,"Title") %>' Text='<%# DataBinder.Eval(Container.DataItem,"Title") %>'></asp:HyperLink>
On Page load all the hyperlinks have correct navigate url set, When there is a case where the TItle set to hyperlink is "Criteria/Admission" and now I click that hyperlink, the Pagename value set to hyperlink is changed somehow and to all other hyperlinks from there..
The problem arises only when the text has slash inbetween. How to handle this ? It looks weird to me.
try this
Text='<%# Server.HtmlEncode(DataBinder.Eval(Container.DataItem,"Title")) %>'
Update:
how about setting the text not by attribute?
<asp:HyperLink ID="hypSubSections" runat="server"><%# Server.HtmlEncode(DataBinder.Eval(Container.DataItem,"Title")) %></asp:HyperLink>

ASPxGridView and Eval(string) method

I'm trying to add column to ASPxGridView which would have link to other page:
<Columns>
...
<dxwgv:GridViewDataColumn Caption=" " VisibleIndex="10">
<DataItemTemplate>
<dxe:ASPxHyperLink ID="lnkEdit" runat="server" Text="Edit" NavigateUrl="../Category/Elements/<%# Eval("Id").ToString() %>/Edit"/>
</DataItemTemplate>
</dxwgv:GridViewDataColumn>
</Columns>
But I get error:
Parser Error Message: The server tag is not well formed.
when I used ' ' instead " " the link href property is "../Category/Elements/<%# Eval("Id").ToString() %>/Edit"
I don't think you can put databinding elements into the middle of the attribute value. The entire value needs to be within the <% %>:
NavigateUrl='<%# "../Category/Elements/" + Eval("Id").ToString() + "/Edit" %>'
I'm not sure with UI library you're using, but usually the Eval() allows a string format parameter. This would be preferable to the string concatenation approach. You might be able to do:
NavigateUrl='<%# DataBinder.Eval(Container.DataItem, "Id", "../Category/Elements/{0}/Edit") %>'

How to add a hyperlink to my gridview

I want to set hyperlink (on image) in my gridview. When user clicks on that hyperlink, a query string should be generated based on selected value of dropdown list. How to set the hyperlink in gridview and how to form query string for that hyperlink?
Thanks in advance..
You can simply Cancatinate the value of your dropdown to NavigateUrl property of hyperlink
<ItemTemplate>
<asp:HyperLink ID="hlEdit" runat="server"
NavigateUrl='<%# Eval("ID", "PageName.aspx?ID={0}" + "&TID=" + ddl.SelectedValue) %>'
ImageUrl="~/Images/edit.png"></asp:HyperLink>
</ItemTemplate>
Edit:
<ItemTemplate>
<asp:ImageButton ID="hlEdit" runat="server"
PostBackUrl='<%# Eval("ID", "PageName.aspx?ID={0}" + "&TID=" + ddl.SelectedValue) %>'
ImageUrl="~/Images/edit.png"></asp:ImageButton>
</ItemTemplate>
You will probably need javascript for this.
Add an 'onclick' attribute to your images
In the onclick handler, you retrieve the dropdownlist value and compose your query
Set the composed url to the href of your link
Some more detailed information would be useful to be able to provide you with some code..
Are you using an asp HyperLink, ImageButton, ...?
You could for example use the OnClientClick property in case you would be using an ImageButton.

Resources