473,397 Members | 1,985 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

datagrid-how to get cell value(hyperlink column)

Hi I have a data grid with a hyperlink column. the colum has numbers like
00001,000002, ect. Just wondering how to get the text value of the cell as
tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
returns a blank string. It seems to work ok for the other columns that are
just regular datagrid columns, not hyperlink types.
Thanks.
--
Paul G
Software engineer.
Nov 18 '05 #1
9 14994
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi I have a data grid with a hyperlink column. the colum has numbers like
00001,000002, ect. Just wondering how to get the text value of the cell
as
tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
returns a blank string. It seems to work ok for the other columns that
are
just regular datagrid columns, not hyperlink types.
Thanks.
--
Paul G
Software engineer.

Nov 18 '05 #2
thanks for the information. Can this be in the page load routine as I am
getting an error trying to use e.? Thanks Paul.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi I have a data grid with a hyperlink column. the colum has numbers like
00001,000002, ect. Just wondering how to get the text value of the cell
as
tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
returns a blank string. It seems to work ok for the other columns that
are
just regular datagrid columns, not hyperlink types.
Thanks.
--
Paul G
Software engineer.


Nov 18 '05 #3
Hi,
I am getting an invalid cast on the following line, put it in a
ItemDataBound event.
CType(datagrid.Columns(0), HyperLinkColumn).Text = "foobar"
just wondering if you may know what is wrong, thanks Paul.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi I have a data grid with a hyperlink column. the colum has numbers like
00001,000002, ect. Just wondering how to get the text value of the cell
as
tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
returns a blank string. It seems to work ok for the other columns that
are
just regular datagrid columns, not hyperlink types.
Thanks.
--
Paul G
Software engineer.


Nov 18 '05 #4
had the wrong column number.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
Hi I have a data grid with a hyperlink column. the colum has numbers like
00001,000002, ect. Just wondering how to get the text value of the cell
as
tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
returns a blank string. It seems to work ok for the other columns that
are
just regular datagrid columns, not hyperlink types.
Thanks.
--
Paul G
Software engineer.


Nov 18 '05 #5
No. You have to use it in the ItemDataBound event of you datagrid.

Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
thanks for the information. Can this be in the page load routine as I am
getting an error trying to use e.? Thanks Paul.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Hi I have a data grid with a hyperlink column. the colum has numbers
> like
> 00001,000002, ect. Just wondering how to get the text value of the
> cell
> as
> tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
> returns a blank string. It seems to work ok for the other columns that
> are
> just regular datagrid columns, not hyperlink types.
> Thanks.
> --
> Paul G
> Software engineer.


Nov 18 '05 #6
Hi almost have it working but not quite. The hyperlink column has a
different value for each row, data being returned from a stored procedure
then going into a dataset.
The code below returns the column text field of the hyperlink value but not
the actual cell value. I have

st_temp = CType(dg_searchlog.Columns(6), HyperLinkColumn).DataTextField
and I get Data_Item_Number which is the correct text field selected in the
data grid for that column but I need the cell values for each row out of the
column.
if I use
st_temp = CType(dg_searchlog.Columns(6), HyperLinkColumn).Text
it returns a blank string.
"Greg Burns" wrote:
No. You have to use it in the ItemDataBound event of you datagrid.

Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
thanks for the information. Can this be in the page load routine as I am
getting an error trying to use e.? Thanks Paul.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Hi I have a data grid with a hyperlink column. the colum has numbers
> like
> 00001,000002, ect. Just wondering how to get the text value of the
> cell
> as
> tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
> returns a blank string. It seems to work ok for the other columns that
> are
> just regular datagrid columns, not hyperlink types.
> Thanks.
> --
> Paul G
> Software engineer.


Nov 18 '05 #7
Looks like it is not possible to get the individual cell value of the
hyperlink column when using a data text field data source. The .text member
returns the string entered in the text entry of the property builder of the
datagrid. Using this sets the text the same for each row of the hyperlink
column. Setting the text field to a datasource will allow each row (cell
text) to be different for the hyperlink column but there does not seem to be
any method to return the value.

"Greg Burns" wrote:
No. You have to use it in the ItemDataBound event of you datagrid.

Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
thanks for the information. Can this be in the page load routine as I am
getting an error trying to use e.? Thanks Paul.

"Greg Burns" wrote:
If you had a HyperLink in a template column I would use this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
With CType(e.Item.Cells(column number).FindControl("control name"),
HyperLink)
.ToolTip = "Foobar"
.NavigateUrl = "Foobar"
.Text="Foobar"
End With
End If

But since you are using a HyperLinkColumn, I googled and found this:

If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
ListItemType.AlternatingItem Then
CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
End If

HTH,
Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:A4**********************************@microsof t.com...
> Hi I have a data grid with a hyperlink column. the colum has numbers
> like
> 00001,000002, ect. Just wondering how to get the text value of the
> cell
> as
> tempstring = datagrid.Items(rownumber).Cells.Item(column number).Text
> returns a blank string. It seems to work ok for the other columns that
> are
> just regular datagrid columns, not hyperlink types.
> Thanks.
> --
> Paul G
> Software engineer.


Nov 18 '05 #8
Hmm. Sorry to hear that. Hadn't actually tried it.

Personally, I would just switch and make that column a template column. Add
a <asp:hyperlink runat=server id=MyHyperLink /> control and use FindControl
to modify it in ItemDataBound.

Greg
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Looks like it is not possible to get the individual cell value of the
hyperlink column when using a data text field data source. The .text
member
returns the string entered in the text entry of the property builder of
the
datagrid. Using this sets the text the same for each row of the hyperlink
column. Setting the text field to a datasource will allow each row (cell
text) to be different for the hyperlink column but there does not seem to
be
any method to return the value.

"Greg Burns" wrote:
No. You have to use it in the ItemDataBound event of you datagrid.

Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
> thanks for the information. Can this be in the page load routine as I
> am
> getting an error trying to use e.? Thanks Paul.
>
> "Greg Burns" wrote:
>
>> If you had a HyperLink in a template column I would use this:
>>
>> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
>> ListItemType.AlternatingItem Then
>> With CType(e.Item.Cells(column number).FindControl("control name"),
>> HyperLink)
>> .ToolTip = "Foobar"
>> .NavigateUrl = "Foobar"
>> .Text="Foobar"
>> End With
>> End If
>>
>> But since you are using a HyperLinkColumn, I googled and found this:
>>
>> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
>> ListItemType.AlternatingItem Then
>> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
>> End If
>>
>> HTH,
>> Greg
>>
>> "Paul" <Pa**@discussions.microsoft.com> wrote in message
>> news:A4**********************************@microsof t.com...
>> > Hi I have a data grid with a hyperlink column. the colum has
>> > numbers
>> > like
>> > 00001,000002, ect. Just wondering how to get the text value of the
>> > cell
>> > as
>> > tempstring = datagrid.Items(rownumber).Cells.Item(column
>> > number).Text
>> > returns a blank string. It seems to work ok for the other columns
>> > that
>> > are
>> > just regular datagrid columns, not hyperlink types.
>> > Thanks.
>> > --
>> > Paul G
>> > Software engineer.
>>
>>
>>


Nov 18 '05 #9
ok sounds like a good idea. thanks.

"Greg Burns" wrote:
Hmm. Sorry to hear that. Hadn't actually tried it.

Personally, I would just switch and make that column a template column. Add
a <asp:hyperlink runat=server id=MyHyperLink /> control and use FindControl
to modify it in ItemDataBound.

Greg
"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:EB**********************************@microsof t.com...
Looks like it is not possible to get the individual cell value of the
hyperlink column when using a data text field data source. The .text
member
returns the string entered in the text entry of the property builder of
the
datagrid. Using this sets the text the same for each row of the hyperlink
column. Setting the text field to a datasource will allow each row (cell
text) to be different for the hyperlink column but there does not seem to
be
any method to return the value.

"Greg Burns" wrote:
No. You have to use it in the ItemDataBound event of you datagrid.

Greg

"Paul" <Pa**@discussions.microsoft.com> wrote in message
news:68**********************************@microsof t.com...
> thanks for the information. Can this be in the page load routine as I
> am
> getting an error trying to use e.? Thanks Paul.
>
> "Greg Burns" wrote:
>
>> If you had a HyperLink in a template column I would use this:
>>
>> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
>> ListItemType.AlternatingItem Then
>> With CType(e.Item.Cells(column number).FindControl("control name"),
>> HyperLink)
>> .ToolTip = "Foobar"
>> .NavigateUrl = "Foobar"
>> .Text="Foobar"
>> End With
>> End If
>>
>> But since you are using a HyperLinkColumn, I googled and found this:
>>
>> If e.Item.ItemType = ListItemType.Item OrElse e.Item.ItemType =
>> ListItemType.AlternatingItem Then
>> CType(grid.Columns(0), HyperLinkColumn).Text = "foobar"
>> End If
>>
>> HTH,
>> Greg
>>
>> "Paul" <Pa**@discussions.microsoft.com> wrote in message
>> news:A4**********************************@microsof t.com...
>> > Hi I have a data grid with a hyperlink column. the colum has
>> > numbers
>> > like
>> > 00001,000002, ect. Just wondering how to get the text value of the
>> > cell
>> > as
>> > tempstring = datagrid.Items(rownumber).Cells.Item(column
>> > number).Text
>> > returns a blank string. It seems to work ok for the other columns
>> > that
>> > are
>> > just regular datagrid columns, not hyperlink types.
>> > Thanks.
>> > --
>> > Paul G
>> > Software engineer.
>>
>>
>>


Nov 18 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Cliff Benoist | last post by:
I have a case where I would like to add a textbox to a datagrid column header. I would like to use a user control or custom control to create a reusable control. The textbox will filter the...
0
by: Randy | last post by:
Hello, I'm trying to find out if there is a way to set a DataGrid column width (or tableStyle column width) to be auto-expanded to encompass the widest text in that column...to be auto-expanded...
3
by: bismarkjoe | last post by:
Hello, I am trying to set the widths on the columns of a DataGrid component, and I'm not sure if I'm doing it correctly. My code is below: //load some inital data table = db.GetDataTable(...
16
by: tshad | last post by:
I am trying to center a button in a datagrid column in asp.net and it doesn't seem to work. I have the following: <asp:TemplateColumn ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center">...
0
by: Bidarkota | last post by:
Can i set the color of the entire DataGrid Column (for example to blue) when i click the header of the DataGrid Column. If it is possible please help with sample code. Thanks in Advance.
1
by: nate axtell | last post by:
In VB .NET I load the contents of an Excel or comma seperated values file into a dataGrid (via a datatable). One of the columns has a comma in the name of the column. So for the comma separated...
2
by: Starbuck | last post by:
Hi Is there anyway of capturing when the users adjusts the width of a datagrid column so the new column width can be stored. Thanks in advance
1
by: Veeves | last post by:
I would like to change the width of a datagrid column at run time. I have noticed when creating a datagrid, if the header text is shorter than the data in the column, then the column width set by...
4
by: gane | last post by:
Hi, I am creating datagrid bound column dynamically and need to check if a datagrid column already exists?Is there a way to check this? thanks gane
0
by: ashinamdev | last post by:
Hi I have a probelm I am using the datagrid control in my asp.net web page. I want to resize the datagrid column at runtime. User can be able to resize the column width according to his...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.