Solved

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

Posted on 2014-11-12
5
94 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
ID: 40439841
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
ID: 40440323
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
ID: 40440528
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
ID: 40442882
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
ID: 40442954
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

IP addresses can be stored in a database in any of several ways.  These ways may vary based on the volume of the data.  I was dealing with quite a large amount of data for user authentication purpose, and needed a way to minimize the storage.   …
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

730 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