Solved

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

Posted on 2014-11-12
5
92 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
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

770 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