C# .NET - Hyperlink Field in Gridview
Asked By Shyam sasidharan on 28-Apr-09 01:05 AM
hi guys i have a gridview which has a Hyperlink field. I have to generate a unique URL for each row in the column. i have written this code.
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID" DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/"/>
This InquiryID in the datasource contains no such as 87750 etc. These nos are to be appende to the URL as custdb://iq=87750 for example. but i am not able so see the hyperlink option in the gridview??
what is wrong in my code?? please help!!
Santhosh N replied to Shyam sasidharan on 28-Apr-09 01:13 AM
set autogeneratecolumns=false in the gridview
<asp:GridView id="myGrid" runat="server"
autogeneratecolumns=false
and then add the hyperlink inside the columns collection as below
<columns>
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID"
DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/"/>
...
</columns>this should solve your problem..
sri sri replied to Shyam sasidharan on 28-Apr-09 01:15 AM
hi,
check the below link
http://authors.aspalliance.com/aspxtreme/webforms/controls/addinghyperlinkfieldstogridview.aspx
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 01:22 AM
Hi,
here is the format for this...
<asp:HyperLinkField HeaderText="test" DataNavigateUrlFormatStringcustdb://iq={0}" DataNavigateUrlFields="InquiryID" Text="test" />
and you can pass any number of querystrings like this
<
asp:HyperLinkField HeaderText="test" DataNavigateUrlFormatString="~/default.aspx?id={0}&id2={1}" DataNavigateUrlFields="Name,Id" Text="test" />
hi santhosh
Shyam sasidharan replied to Santhosh N on 28-Apr-09 01:24 AM
I tried doing it!! that is the same code that i have written but the hyperlink in not appearing on the page!!
hi vasanth
Shyam sasidharan replied to Vasanthakumar D on 28-Apr-09 01:28 AM
hi have done the same thing in my code!! but the Hyperlink is not appearing in the page!! please help!!
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID" DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/"/>
you have missed text property
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 01:29 AM
Hi,
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID" DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/" Text="test"/>
hi vasanth
Shyam sasidharan replied to Vasanthakumar D on 28-Apr-09 01:43 AM
Hi tried that as well but in vain!! i am not able to see the hyperlink at all in the page!! dont know why!! The new code written as suggested by you is as follows
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID" DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/" Text="test"/>
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 01:48 AM
Hi,
can you post your gridview HTML?
HTML of gridview
Shyam sasidharan replied to Vasanthakumar D on 28-Apr-09 01:51 AM
<asp:GridView ID="GridView1" runat="server" Height="281px" Width="784px" AutoGenerateColumns="False">
<Columns>
<asp:BoundField HeaderText="Date Created" DataField="inqdate" />
<asp:BoundField HeaderText="Priority" DataField="priority" />
<asp:HyperLinkField HeaderText="Inquiry No" DataTextField="InquiryID" DataNavigateUrlFields="InquiryID" DataNavigateUrlFormatString="custdb://iq={0}/" Text="{0}"/>
<asp:BoundField HeaderText="Inquiry Type" DataField="inqtype" />
<asp:BoundField HeaderText="Inquiry Resolved" DataField="resolved" />
</Columns>
</asp:GridView>
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 01:56 AM
Hi shyam,
problem with your URL...
your URL custdb://iq= is not a valid one... give valid one.... thats why you didnot get URL in pages...
where do you want ot pass the values?
hi vasanth
Shyam sasidharan replied to Vasanthakumar D on 28-Apr-09 02:04 AM
i have a software called customerdb which should pop up!! it works when i take windows run and type the command custdb://iq="some no"
so i have to take the iq no and pass it to the url!! thats how it works!! but if i use navigateurl and assign navigateurl="custdb://iq=87750" the software pops up!! i am in a dilemma!! if i use navigateurl i am able to see the hyperlink!! or else the value is only appearing as text and there is no hyperlink to click!!
yes
Ravenet Rasaiyah replied to Shyam sasidharan on 28-Apr-09 02:21 AM
Hi
custdb://iq="some no" is it working on the Internter explore or Firebox?, because of i'm wondering, how you have url like that.Please check with IE.
thank you
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 02:22 AM
Hi,
for this you have to try some thing like this
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="hyp" runat="server" Text='<%# Eval("Id") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
and row databound event
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
HyperLink hy = (HyperLink)e.Row.FindControl("hyp");
hy.NavigateUrl = "custdb://iq=" + e.Row.Cells[cellno of inquiry id].Text;
}
}
hi vasanth
Shyam sasidharan replied to Vasanthakumar D on 28-Apr-09 02:43 AM
but can you help me do the same with hyperlink field in gridview?? how do i use the same with hypertextfield as there is no attribute called ID for hyperlink Field!!
Vasanthakumar D replied to Shyam sasidharan on 28-Apr-09 02:53 AM
Hi,
try this. this will help you ...
<asp:TemplateField>
<ItemTemplate>
<a href='custdb://iq=<%# Eval("InquiryID") %>'><%# Eval("InquiryID")%> </a>
</ItemTemplate>
</asp:TemplateField>