Hi,
I am using NetAdvantage .Net 2007 Vol 2 for ASP.Net. I have a databound WebGrid that has an unbound checkbox column as the first column to select one or more rows to update. Once rows have been selected, the user will click a button to bring up a form/dialog to select values to update all the selected rows with those values. The idea is to avoid having the user manually update each individual row, since the data is going be repetitive.
Has anyone done something similar or have any ideas on the best way to implement this? Thanks
I've done exactly that, using the following code. One pitfall is the fact that Grid.Rows contains rows for all grouping levels and all bands. To get around this, I implemented a recursive function that processed only leaf-node rows.
'Traverses an UltraWebGrid.RowsCollection, looking 'for checked boxes in one column, and adding 'corresponding values from another column to a'results collection. Processes only leaf node rows.Private Sub ScanRowsCollection( _ ByRef rRows As RowsCollection, _ ByVal vCheckboxColumnKey As String, _ ByVal vValueColumnKey As String, _ ByRef rValues As Collection) Dim lResult As New Collection Dim lCheckCell As UltraGridCell Dim lValueCell As UltraGridCell For Each lRow As UltraGridRow In rRows If lRow.HasChildRows Then 'only scan lowest band ScanRowsCollection(lRow.Rows, vCheckboxColumnKey, _ vValueColumnKey, rValues) Else lCheckCell = lRow.Cells.FromKey(vCheckboxColumnKey) lValueCell = lRow.Cells.FromKey(vValueColumnKey) If lCheckCell IsNot Nothing And lValueCell IsNot Nothing Then If CBool(lCheckCell.Value) Then 'process checked row here End If End If End If Next End Sub
Dim lResult As New Collection Dim lCheckCell As UltraGridCell Dim lValueCell As UltraGridCell
If lRow.HasChildRows Then 'only scan lowest band
ScanRowsCollection(lRow.Rows, vCheckboxColumnKey, _ vValueColumnKey, rValues)
Else
lCheckCell = lRow.Cells.FromKey(vCheckboxColumnKey) lValueCell = lRow.Cells.FromKey(vValueColumnKey)
If lCheckCell IsNot Nothing And lValueCell IsNot Nothing Then If CBool(lCheckCell.Value) Then 'process checked row here End If End If
End If
Next
End Sub
Thanks,
That is what I am doing to check if the row was selected. The problem I am having is how to go about changing the values for the selected rows in the grid programatically. So when the user clicks the Apply button, all the selected rows are updated with the values selected in the form. I have tried many things but nothing seems to work to update botht the grid and the database - I just don't know how to go about processing the rows.
A sample of what the page looks like is below. There is a dropdown for the user to select an "action" at the top, and when they click apply I need that action value to be used to update the "action" column for all the selected rows in the grid.
<asp:Label ID="lblAction" runat="server" Text="Action"></asp:Label>
<asp:DropDownList ID="ddlAction" runat="server" DataSourceID="ActionDataSource" DataTextField="Action" DataValueField="Action">
<asp:Button ID="btnApply" runat="server" Text="Apply" OnClick="btnApply_Click" />
<igtbl:UltraWebGrid ID="UltraWebGrid1" runat="server" Browser="Xml" DataSourceID="SqlDataSource1" DataMember="DefaultView" DataKeyField="DocID">
<Bands><igtbl:UltraGridBand SelectTypeRow="Extended" DataKeyField="DocID" AllowUpdate="RowTemplateOnly">
<Columns>
<igtbl:TemplatedColumn BaseColumnName="selectAll" AllowRowFiltering="False" Width="50px" Key="selectAll" Type="CheckBox" AllowUpdate="Yes" SortIndicator="Disabled">
<HeaderTemplate><input id="chkHeaderCheck" type="checkbox" onclick="SelectAll(0)"></HeaderTemplate>
</igtbl:TemplatedColumn>
<igtbl:UltraGridColumn BaseColumnName="DocID" DataType="System.Int32" Hidden="True" IsBound="True" Key="DocID">
<Header Caption="DocID"></Header>
<Footer><RowLayoutColumnInfo OriginX="1" /></Footer>
</igtbl:UltraGridColumn>
<igtbl:UltraGridColumn BaseColumnName="Action" IsBound="True" Key="Action" Width="250px" AllowUpdate="RowTemplateOnly">
<Header Caption="Action"><RowLayoutColumnInfo OriginX="2" /></Header>
<Footer><RowLayoutColumnInfo OriginX="2" /></Footer>
...
</igtbl:UltraWebGrid>
Thanks again.