A
Alex Shirley
Hi
I have a problem with a datagrid, I need to get a value from one of
the columns from when I hit a hyperlink column. The hyperlink column
is the first column, and the second column is the value (which is in
fact "ContactID").
The event that fires when I click on the hyperlink column definitely
works.
When I add in the ContactID column in the html like this (in the
datagrid)
<asp:BoundColumn DataField="Contact ContactID" SortExpression="Contact
ContactID" HeaderText="Contact ContactID"></asp:BoundColumn>
And click on the hyperlink button, then no problem, the value is
returned when I put this code in the button event handler:
-------------------------------------------------------------------------------
Response.Write("ContactID=" & e.Item.Cells(1).Text)
Response.End
-------------------------------------------------------------------------------
However if I create the bound column using the following back end code
(which will show the column):
-------------------------------------------------------------------------------
showdgcolumn(DataGridWhatever, "ContactID", "Contact ContactID")
.......>
Public Sub showdgcolumn(ByVal mydatagrid As DataGrid, ByVal
strHeadertext As String, ByVal strdatafield As String)
Dim col As BoundColumn = New BoundColumn
col.HeaderText = strHeadertext
col.DataField = strdatafield
col.SortExpression = strHeadertext
mydatagrid.Columns.Add(col)
End Sub
-------------------------------------------------------------------------------
Now in this case if I click on the view hyperlink button I get
"Specified argument was out of the range of valid values. Parameter
name: index", using the same event handler code above.
Note the column is in exactly the same position. I just don't seem to
get the index value if I generate the column using back end VB code.
Any ideas?
Many thanks!
Alex
I have a problem with a datagrid, I need to get a value from one of
the columns from when I hit a hyperlink column. The hyperlink column
is the first column, and the second column is the value (which is in
fact "ContactID").
The event that fires when I click on the hyperlink column definitely
works.
When I add in the ContactID column in the html like this (in the
datagrid)
<asp:BoundColumn DataField="Contact ContactID" SortExpression="Contact
ContactID" HeaderText="Contact ContactID"></asp:BoundColumn>
And click on the hyperlink button, then no problem, the value is
returned when I put this code in the button event handler:
-------------------------------------------------------------------------------
Response.Write("ContactID=" & e.Item.Cells(1).Text)
Response.End
-------------------------------------------------------------------------------
However if I create the bound column using the following back end code
(which will show the column):
-------------------------------------------------------------------------------
showdgcolumn(DataGridWhatever, "ContactID", "Contact ContactID")
.......>
Public Sub showdgcolumn(ByVal mydatagrid As DataGrid, ByVal
strHeadertext As String, ByVal strdatafield As String)
Dim col As BoundColumn = New BoundColumn
col.HeaderText = strHeadertext
col.DataField = strdatafield
col.SortExpression = strHeadertext
mydatagrid.Columns.Add(col)
End Sub
-------------------------------------------------------------------------------
Now in this case if I click on the view hyperlink button I get
"Specified argument was out of the range of valid values. Parameter
name: index", using the same event handler code above.
Note the column is in exactly the same position. I just don't seem to
get the index value if I generate the column using back end VB code.
Any ideas?
Many thanks!
Alex