Solved

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

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
This code tracks birthdays 3 61
VB.Net How to Exit Sub - Exit Form??? 5 51
Change Format on Data when exporting to Excel 4 23
Crystal reports vb.net 2 20
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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:…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

861 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

22 Experts available now in Live!

Get 1:1 Help Now