Solved

how do I make  cells in gridview respond to click when they are boundfields

Posted on 2014-11-12
5
89 Views
Last Modified: 2014-11-14
I have one field that has the ip address of a printer,  when you type the ip address of a printer in explorer the printers web page opens.
right now the ip address is stored in a string format and in a boundfield because I don't want anyone editing the cell.
Have tried to make the column hyperlink but it says data is of wrong type.
data stored in field is http:\\192.168.9.159.
the data comes from a datatable that I create in memory and is bound to my gridview; so it is not connected to a database.
I would like to be able to click on this cell and have explorer open the printer.
The question here is do I change the data to a different format? somehow change the column in the gridview?  The question boils down to, how do I make the cell a hyperlink and what format do I have to put in the datatable so this works.

thanks
gary
0
Comment
Question by:javagair
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
Maybe using url formatstring. Something like this will work?

<Columns>
<asp:HyperLinkField
     DataNavigateUrlFields="Printer"
     DataNavigateUrlFormatString="page.aspx?printerID={0}"
     DataTextField="Printer"
     HeaderText="Print" />
 </Columns>
0
 

Author Comment

by:javagair
Comment Utility
thanks sammySeltzer
don't get data type error

getting ip address from another table, first a concatenate it to http://
then convert it to a uri
ipaddress = "http://" & Dst.Tables("printerequip").Rows(i).Item(3).ToString()
            Dim ipaddressu As New Uri(ipaddress)

type in the datatable is now Uri
table.Columns.Add("Ipaddress", GetType(Uri))

the web page:
<asp:HyperLinkField
                    DataNavigateUrlFields="Ipaddress"
                     DataNavigateUrlFormatString="page.aspx?printerID={0}"
                   DataTextField="Ipaddress"
                     HeaderText="Ipaddress" />

everything shows up fine on the web page now, but the cell is still locked like a boundfield.
how do I get the cell to accept a click so I can open the web page of the printer?

thanks gary
0
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
Ok, let's try using template field then:

                <asp:TemplateField HeaderText="IP Address" SortExpression="Ipaddress">
                 <ItemTemplate>
                   <asp:HyperLink ID="Ipaddress" runat="server" Target="_blank" HeaderText="IP Address" NavigateUrl='<%# Eval("Ipaddress","page.aspx?printerID={0}") %>' Text = '<%# Eval("Ipaddress") %>' />
                 </ItemTemplate> 
               </asp:TemplateField>

Open in new window


Remove sortExpression if you don't want it.

Remove Target="_blank" if you don't want it.
0
 

Author Comment

by:javagair
Comment Utility
sammySeltzer
line in gridview looks good and works.
I get a new web page, but I get an error that it can not find  /inventory/page.aspx.  Inventory is the folder that my code is installed in, since this is the first attempt at asp.net web I don't know what is expected to be in page.aspx.
if I put an ip address in a email then click on it I go to that place, is there a way in your instruction line to tell it just to go to the ip address and not to another page in the project?

thanks
gary
0
 

Author Comment

by:javagair
Comment Utility
solved my own problem by getting rid of http://192.168.2.150 and replaced with
//192.168.2.150 which actually opens the printer web page.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

This article describes relatively difficult and non-obvious issues that are likely to arise when creating COM class in Visual Studio and deploying it by professional MSI-authoring tools. It is assumed that the reader is already familiar with the cla…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
This video discusses moving either the default database or any database to a new volume.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now