P
Phillip N Rounds
I have a DataGrid in a web form (ASP1.1, C#, VS 2003) that I'm trying to add
some functionality to, and I can't figure out how to do int.
The existing DataGrid has several databound columns and a Template Columns,
into which I put buttons. When the user clicks on the 'Do It' button, the
selection is recorded in an underlying database, and (almost) everything is
fine. One thing I would like to improve in the existing version concerns
the state of the datagrid in the postback. I would like to scroll to the
row the user just clicked on.
I have to add DropDownList controls to some of the rows, based on database
driven considerations. I added template columns to the DataGrid, and
inserted DropDownLists into these columns, as well as two invisible
databound columns, Number_Of_Category1_Fields, Number_Of_Category2_Fields.
In the DataTier I add fields Number_Of_Category1_Fields,
Number_of_Category2_Field to the main table, and added tables
Category1_Fields, Category2_Fields.
In the Page_Load method I create & populate the DataGrid.
I loop over the DataGrid.Items collection, and if the entries for
Number_Of_Category1_Fields > 0, I retrieve the entries from the table
Category1_Fields and insert them into the appropriate DropDownList ( same
for Category2 ), setting the DropDownList.Visible = true
In the DataGridItemEvent, i.e. user clicked the 'Do It' button, I check to
see if the DropDownLists are populated, if so I retrieve the selected value
and insert these into the database as appropriate. Again, all works well
My problem is how to trap instances where the user clicks the 'Do It'
button where they haven't made a selection in one or more of the
DropDownLists. I would like to do this before the PostBack, so the error
trapping can't be performed in the 'Do It' button. I was thinking of having
the 'Do It' buttons disabled, and enabling them with JavaScript when the
user selects from the DropDownLists, but I don't know how to add that
functionality within the context of a DataGrid ( i.e. how does one retrieve
the ControlID of the DropDownList to get the names of the other
DropDownList and the button? )
So, my question is, how does one do this well?
Thanks
Phil
some functionality to, and I can't figure out how to do int.
The existing DataGrid has several databound columns and a Template Columns,
into which I put buttons. When the user clicks on the 'Do It' button, the
selection is recorded in an underlying database, and (almost) everything is
fine. One thing I would like to improve in the existing version concerns
the state of the datagrid in the postback. I would like to scroll to the
row the user just clicked on.
I have to add DropDownList controls to some of the rows, based on database
driven considerations. I added template columns to the DataGrid, and
inserted DropDownLists into these columns, as well as two invisible
databound columns, Number_Of_Category1_Fields, Number_Of_Category2_Fields.
In the DataTier I add fields Number_Of_Category1_Fields,
Number_of_Category2_Field to the main table, and added tables
Category1_Fields, Category2_Fields.
In the Page_Load method I create & populate the DataGrid.
I loop over the DataGrid.Items collection, and if the entries for
Number_Of_Category1_Fields > 0, I retrieve the entries from the table
Category1_Fields and insert them into the appropriate DropDownList ( same
for Category2 ), setting the DropDownList.Visible = true
In the DataGridItemEvent, i.e. user clicked the 'Do It' button, I check to
see if the DropDownLists are populated, if so I retrieve the selected value
and insert these into the database as appropriate. Again, all works well
My problem is how to trap instances where the user clicks the 'Do It'
button where they haven't made a selection in one or more of the
DropDownLists. I would like to do this before the PostBack, so the error
trapping can't be performed in the 'Do It' button. I was thinking of having
the 'Do It' buttons disabled, and enabling them with JavaScript when the
user selects from the DropDownLists, but I don't know how to add that
functionality within the context of a DataGrid ( i.e. how does one retrieve
the ControlID of the DropDownList to get the names of the other
DropDownList and the button? )
So, my question is, how does one do this well?
Thanks
Phil