I am trying to retrieve the text within each cell in a datagrid in
order to change the color of each cell, depending on the value within
that cell.
This works fine on the cells that are bound columns, but returns an
empty string for the cells that are hyperlink columns.
Here is the code to retrive the text:
Private Sub DataGrid1_ItemD ataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemD ataBound
Dim x As Integer
For x = 0 To e.Item.Cells.Co unt - 1
Response.Write( e.Item.Cells(x) .Text)
Next
End Sub
I have also tried, which gives me the error:
"Specified argument was out of the range of valid values. Parameter
name: index
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.
Exception Details: System.Argument OutOfRangeExcep tion: Specified
argument was out of the range of valid values. Parameter name: index
Source Error:
Line 144: Dim H1 As HyperLink
Line 145: For x = 0 To e.Item.Cells.Co unt - 1
Line 146: H1 = e.Item.Cells(8) .Controls(1)
Line 147: Response.Write( H1.Text)
Line 148: Next"
Private Sub DataGrid1_ItemD ataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemD ataBound
Dim x As Integer
Dim H1 As HyperLink
For x = 0 To e.Item.Cells.Co unt - 1
H1 = e.Item.Cells(8) .Controls(1)
Response.Write( H1.Text)
Next
End Sub
This is how I am creating the datagrid:
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeCompo nent()
Dim strSql As String = "exec dbo.uspSummaryM atrix"
Dim strCnn As String = "data source=xxxx;int egrated
security=false; initial catalog=COPS;ui d=xxxx;pwd=xxxx "
objCnn = New SqlConnection(s trCnn)
objCmd = New SqlCommand
objCmd.CommandT ext = "dbo.uspSummary Matrix"
objCmd.CommandT ype = CommandType.Sto redProcedure
objCmd.Connecti on = objCnn
objCmd.Paramete rs.Add(New SqlParameter("@ ItemID",
System.Data.Sql DbType.VarChar, 255))
objCmd.Paramete rs("@ItemID").V alue = Request.QuerySt ring("ID")
objCnn.Open()
Dim dReader As SqlDataReader
dReader = Nothing
dReader = objCmd.ExecuteR eader()
Dim i As Integer
Dim count As Integer
count = 0
DataGrid1.GridL ines = GridLines.Both
DataGrid1.Allow Sorting = True
DataGrid1.Borde rColor = Color.SlateGray
DataGrid1.Borde rStyle = BorderStyle.Sol id
DataGrid1.ShowH eader = True
DataGrid1.AutoG enerateColumns = False
DataGrid1.BackC olor = Color.White
DataGrid1.Alter natingItemStyle .BackColor = Color.LightGray
DataGrid1.ItemS tyle.ForeColor = Color.DarkSlate Blue
DataGrid1.ItemS tyle.BackColor = Color.White
DataGrid1.Heade rStyle.Font.Bol d = True
DataGrid1.Heade rStyle.ForeColo r = Color.White
DataGrid1.Heade rStyle.BackColo r = Color.DarkSlate Blue
DataGrid1.Width = Unit.Percentage (100)
DataGrid1.CellP adding = 2
Dim datagridcol
Dim strcolor As String
Do While dReader.Read
If count = 0 Then
For i = 0 To dReader.FieldCo unt - 1
If InStr(dReader.G etName(i), "container" ) Then
datagridcol = New BoundColumn
datagridcol.hea dertext =
Replace(dReader .GetName(i), "c", "C")
datagridcol.dat afield = dReader.GetName (i)
DataGrid1.Colum ns.Add(datagrid col)
End If
If InStr(dReader.G etName(i), "Word") Then
datagridcol = New HyperLinkColumn
datagridcol.Hea derText =
Replace(dReader .GetName(i), "Word", "")
datagridcol.Dat atextField = dReader.GetName (i)
End If
If InStr(dReader.G etName(i), "Link") Then
datagridcol.dat anavigateurlfie ld =
dReader.GetName (i)
datagridcol.dat anavigateurlfor matstring =
"UsageDocuments 2.aspx?ID={0}"
datagridcol.tar get = "iframedocument "
DataGrid1.Colum ns.Add(datagrid col)
End If
Next
End If
count = count + 1
Loop
dReader.Close()
objDataAdapter = New SqlDataAdapter( objCmd)
objDataSet = New DataSet
objDataView = New DataView
objDataAdapter. Fill(objDataSet )
objDataView.Tab le = objDataSet.Tabl es(0)
DataGrid1.DataS ource = objDataView
DataGrid1.DataB ind()
objCnn.Close()
End Sub
I have also considered creating a template column with a hyperlink
inside the template, but I'm not too sure how to do this or access the
text value within the template column.
Any advice or help is greatly appreciated!
Thank you in advance!
Jill 1 2648
I was able to fix my problem by doing the following. I kept my code
for creating the datagrid the same. Since I know the first column is
always a bound column and the rest are always hypelink columns (and I
don't care what is in the bound column), I am disregarding the first
column all together and starting at 1 in my loop instead of 0.
Private Sub DataGrid1_ItemD ataBound(ByVal sender As Object, ByVal e As
System.Web.UI.W ebControls.Data GridItemEventAr gs) Handles
DataGrid1.ItemD ataBound
Dim x As Integer
Dim h1 As HyperLink
For x = 1 To e.Item.Cells.Co unt - 1
If e.Item.ItemType = ListItemType.It em Or e.Item.ItemType =
ListItemType.Al ternatingItem Then
Select Case CType(e.Item.Ce lls(x).Controls (0),
HyperLink).Text
Case Is = "Approved"
e.Item.Cells(x) .BackColor = Color.Lime
Case Is = "Denied"
e.Item.Cells(x) .BackColor = Color.Red
Case Is = "Identified "
e.Item.Cells(x) .BackColor = Color.Cyan
Case Is = "In Work"
e.Item.Cells(x) .BackColor = Color.Cyan
Case Is = "Restricted "
e.Item.Cells(x) .BackColor = Color.Orange
Case Is = "Retired"
e.Item.Cells(x) .BackColor = Color.Orange
Case Is = "Revoked"
e.Item.Cells(x) .BackColor = Color.Red
Case Is = "Submitted"
e.Item.Cells(x) .BackColor = Color.Yellow
End Select
End If
Next
End Sub This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: George Durzi |
last post by:
Hey all,
I finally found the necessary resources in the Exchange 2003 SDK to "pull"
Contacts out of Exchange and display them on a WebForm. I have been trying
to do this forever, and couldn't until the Exchange 2003 SDK came out.
Here's the code. Hopefully someone else can find this useful.
#region DisplayExchangeContacts
private void DisplayExchangeContacts()
{
|
by: Soul |
last post by:
Hi,
I have a column in my DataGrid which is a Hyperlink Column. Everything work
fine except when I try to get the text of the column using
this.DataGrid.SelectedItem.Cells.Text, I got blank value!!
People from some forum suggest to use ((LinkButton)
this.DataGrid.SelectedItem.Cells.Controls).Text, but I got
"Specified cast is not valid" error.
|
by: GaryB |
last post by:
Does anyone have any idea how to get the text out of a hyperlink column in a
web datagrid?
It's a hyperlink column, not a template column so findcontrol does not work
and there is no apparent name to look for.
myGridItem.cells(0).controls(0) shows no text properties or anything that
points to or contains the text.
It seems quite hidden.
|
by: Tomek R. |
last post by:
Hello !
This post does'nt regard column hyperlink.
I just have single hyperlink and want to create it's NavigateUrl
dynamically.
This is my test page
<form id="Form1" method="post" runat="server">
<asp:HyperLink id="MyHLink" NavigateUrl='<%# geturl("123456") %>'
|
by: Tim::.. |
last post by:
I currently have the following datagrid but want to turn the name and email
column into a hyperlink in the codebehind!
Can someone please tell me how I achieve this!
Thanks
Private Sub createTable()
Dim tbcontacts As DataTable = New DataTable("contacts")
tbcontacts.Columns.Add(" ", System.Type.GetType("System.String"))
| |
by: Fabrice |
last post by:
Hello,
First, thanks to felix for his answer.
But :-( , I'm feeling newbie :! I' don't understand all the situation.
The trouble :
Always in the road whith my Datagrid and my ItemTemplate with a Control
HyperLink.
I would like to fix many properties of this Control Hyperlink in the Code
|
by: david |
last post by:
Hi, all:
I need a help from you about DataGrid control.
I created a DataGrid, dg, in design view of .NET visual Stadio and use the
builder to add a Hyperlink column to dg.
I want to try to assign a column of URLs to this hyperlink column in
programming way (ie., dynamically assignment). However, I can not find a way
to continue doing it.
Do you have ideas about it? Thanks.
|
by: Joe |
last post by:
I have an aspx page (referred to here as page_1) with a datagrid whose first
column contains hyperlinks. When a user clicks one of these hyperlinks, he
will navigate to another aspx page (referred to here as page_2). I need to
cache the value of the link's text (hyperlink.text property) so that I can
use it in the page_load event of page_2.
I've thought of using a hidden field and then calling
Request.Form("hdnClickedLinkText") in the...
|
by: Bauer |
last post by:
I have a datagrid whose rows contain checkbox and
hyperlink columns(containing employee_id field retireved
from database). Once the user checks the checkboxes i
need to get the employee ids whose checkboxes were
checked.
To retireve the employee_id i was looping throught the
datagrid items and trying to get the employeeid from the
first column as
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |