maqskywalker
asked on
referencing 6th column of DataGrid in ASP.NET Web Forms
In this example from this post
https://www.experts-exchange.com/questions/29119837/clearing-a-Header-Row-CheckBox-in-a-DataGrid.html
My DataGrid looked like this:
Notice my CheckBox column is the 1st column of the DataGrid
My button click event looked like this, this worked fine:
In these 2 lines of code:
Dim dgHeader As DataGridItem = DGEmployees.Controls(0).Co ntrols(0)
Dim targetChkBox As CheckBox = dgHeader.Controls(0).Contr ols(1)
What are these references?
.Controls(0).Controls(0)
.Controls(0).Controls(1)
Is that the first row and 1st column?
So if my datagrid looked like this (the checkboxcolumn is the 6th column of my datagrid),
How do I reference the 6th column of my datagrid?
I tried this but it didn't work,
I get this error message:
Specified argument was out of the range of valid values.
Parameter name: index
https://www.experts-exchange.com/questions/29119837/clearing-a-Header-Row-CheckBox-in-a-DataGrid.html
My DataGrid looked like this:
Notice my CheckBox column is the 1st column of the DataGrid
My button click event looked like this, this worked fine:
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' reset header checkbox
Dim dgHeader As DataGridItem = DGEmployees.Controls(0).Controls(0)
Dim targetChkBox As CheckBox = dgHeader.Controls(0).Controls(1)
targetChkBox.Checked = False
CType(DGEmployees.Controls(0).Controls(0).FindControl("DataGridEmployees_SelectAll"), CheckBox).Checked = False
End Sub
In these 2 lines of code:
Dim dgHeader As DataGridItem = DGEmployees.Controls(0).Co
Dim targetChkBox As CheckBox = dgHeader.Controls(0).Contr
What are these references?
.Controls(0).Controls(0)
.Controls(0).Controls(1)
Is that the first row and 1st column?
So if my datagrid looked like this (the checkboxcolumn is the 6th column of my datagrid),
How do I reference the 6th column of my datagrid?
I tried this but it didn't work,
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
' reset header checkbox
Dim dgHeader As DataGridItem = DGEmployees.Controls(0).Controls(0)
Dim targetChkBox As CheckBox = dgHeader.Controls(0).Controls(6)
targetChkBox.Checked = False
CType(DGEmployees.Controls(0).Controls(0).FindControl("DataGridEmployees_SelectAll"), CheckBox).Checked = False
End Sub
I get this error message:
Specified argument was out of the range of valid values.
Parameter name: index
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.