Making Gridview column as hyper link

Posted by Kondapallisrinivas under ASP.NET on 10/28/2013 | Points: 10 | Views : 1413 | Status : [Member] | Replies : 5
Hi All

I have 5 columns(SaleDate, DISTRIBUTORCODE, INVOICENUMBER, SALEQTY, SALEVALUE) in my grid view where the data is coming from the Data base.

Now i want to make the Distributor code as a hyper link and when i click on the distributor code the page redirects to the other page with corresponding saledate,distributorcode,invoicenumber.

Note: The column order is not same every time....So it is not possible to use template field.

Regards
Srinivas Kondapalli




Responses

Posted by: Bandi on: 10/28/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer this link for "Convert a Gridview Column into Hyperlink Fields "
http://www.aspdotnet-suresh.com/2013/01/convert-gridview-column-into-hyperlink.html

Support links
http://social.msdn.microsoft.com/Forums/en-US/13ed6565-d557-4481-8b2d-91f1a31ef1a5/turn-gridview-results-into-hyperlinks?forum=csharplanguage
http://stackoverflow.com/questions/6277653/how-to-set-a-column-in-gridview-as-hyperlink-which-is-autogenerated
http://stackoverflow.com/questions/18189100/get-the-hyperlink-field-value-of-the-selected-record-in-gridview

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kondapallisrinivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/28/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Refer
http://stackoverflow.com/questions/1850247/adding-link-column-to-asp-net-gridview


EDIT:
http://www.ezzylearning.com/tutorial.aspx?tid=8093456
http://asp-net-example.blogspot.in/2008/11/aspnet-asphyperlinkfield-example-how-to_13.html
http://stackoverflow.com/questions/12823422/gridview-hyperlink-field-in-c-sharp

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kondapallisrinivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Samirbhogayta on: 10/29/2013 [Member] Starter | Points: 25

Up
0
Down
hi.. You can do this with the following example's

Example : 1

<asp:GridView runat="server" ID="gvrecords" AutoGenerateColumns="false"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("Name") %>' NavigateUrl='<%# Bind("Name", "~/Images/{0}") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView>

Example : 2

<asp:GridView runat="server" ID="gvrecords" AutoGenerateColumns="false"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="White" DataKeyNames="UserId">
<Columns>
<asp:TemplateField>
<ItemTemplate>
<a href ='<%#"UpdateGridviewvalues.aspx?UserId="+DataBinder.Eval(Container.DataItem,"UserId") %>'> <%#Eval("UserName") %> </a>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserName" HeaderText="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" />
</Columns>
</asp:GridView>

SAMIR
Sr. Software Engineer

Kondapallisrinivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Bandi on: 10/29/2013 [Member] [MVP] Platinum | Points: 25

Up
0
Down
Hi Samir,
Can you provide solution without using TemplateField...

OP requested for that.... you can check the same in NOTE written by srinivas
>>Note: The column order is not same every time....So it is not possible to use template field.

Mark This Response as Answer
--
Chandu
http://www.dotnetfunda.com/images/dnfmvp.gif

Kondapallisrinivas, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Kondapallisrinivas on: 11/2/2013 [Member] Starter | Points: 25

Up
0
Down
Hi All,

i need to redirect to the other page with corresponding Saledate,distributorcode,invoicenumber.

Can any one help me......



Kondapallisrinivas, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response