Solved

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

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

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 29

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

Monthly Recap

May was a big month for new releases from Linux Academy! Take a look at what our team built recently in our blog. You can access the newest releases from our blog.

Question has a verified solution.

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

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

707 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