0
votes

I am using VS 2013 VB. I have a aspxgridview that uses objectdatasource. One of the columns is a command column used as a checkbox named "Select". When the user selects a checkbox and then goes to another page and then back to the page where they made a selected checkbox that check mark is gone. It is not retaining the selection. This is a grid of inventory items. I want to make multiple selections and then click on a button. On the button click I want to open a separate page with the items that were checked. This is to create a work order.

Any ideas of how to accomplish this? I am using VB not C#. Thanks in advance! Below is the grid:

 <dx:ASPxGridView ID="gvInventory" runat="server" AutoGenerateColumns="False" DataSourceID="InventoryDataSource" EnableTheming="True" Theme="Office2003Olive" EnableRowsCache="False" KeyFieldName="ID_Number">
     <Columns>
          <dx:GridViewDataTextColumn FieldName="ID_Number" Visible="False" VisibleIndex="7">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn Caption="Item" FieldName="Item_Number" VisibleIndex="2" Width="25px">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn Caption="Description" FieldName="Item_Description" VisibleIndex="3">
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn Caption="Cost" FieldName="Current_Cost" VisibleIndex="6" Width="15px">
              <PropertiesTextEdit DisplayFormatString="{0:c}">
              </PropertiesTextEdit>
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn Caption="WH" FieldName="Warehouse_Location" VisibleIndex="4" Width="15px">
          </dx:GridViewDataTextColumn>              
          <dx:GridViewDataDateColumn Caption="Date Rcv'd" FieldName="Last_Receipt_Date" VisibleIndex="1" Width="25px">
          </dx:GridViewDataDateColumn>              
          <dx:GridViewDataTextColumn Caption="QTY On Hand" FieldName="Quantity_On_Hand" VisibleIndex="5" Width="20px">                 
              <HeaderStyle Wrap="True" />
          </dx:GridViewDataTextColumn>
          <dx:GridViewDataTextColumn FieldName="Current_Month_Issue_Quantity" Visible="False" VisibleIndex="17">
          </dx:GridViewDataTextColumn>          

          **<dx:GridViewCommandColumn Caption="Select" ShowInCustomizationForm="True" ShowSelectCheckbox="True" VisibleIndex="0">
          </dx:GridViewCommandColumn>**

Changed Checkbox to: *

*<dx:GridViewDataTextColumn ShowInCustomizationForm="True"  VisibleIndex="0">
              <DataItemTemplate>
               <dx:ASPxCheckBox ID="wed" runat="server" OnInit="cb_Init">                            
               </dx:ASPxCheckBox>
               </DataItemTemplate>
              </dx:GridViewDataTextColumn>*

*

Added:

 </dx:ASPxGridView>        
        <dx:ASPxHiddenField ID="hf" runat="server" ClientInstanceName="hf">
        </dx:ASPxHiddenField>

In .vb page added:

 Protected Sub cb_Init(ByVal sender As Object, ByVal e As EventArgs)
        Dim cb As ASPxCheckBox = CType(sender, ASPxCheckBox)
        Dim container As GridViewDataItemTemplateContainer = CType(cb.NamingContainer, GridViewDataItemTemplateContainer)

        Dim key As String = String.Format("{0}_{1}", container.Column.Name, container.VisibleIndex)
        cb.ClientSideEvents.CheckedChanged = String.Format("function(s, e) {{ hf.Set('{0}', s.GetChecked()); }}", key)
        cb.ClientSideEvents.Init = String.Format("function(s, e) {{ s.SetChecked(hf.Get('{0}')); }}", key)
    End Sub

I found this at: https://www.devexpress.com/Support/Center/Question/Details/Q527992

Thank you, KRob for all of your help!

1
for starters, wouldn't AllowEdit="False" need to be set to true, and wouldn't you need an UpdateMethod for your grid? It sounds like you want "Select" to be persistent, and hooking the gridview up to the back-end would be the way to accomplish that. - KRob
I don't want the user to be able to edit any data so it should be false. The datasource doesn't have a binary field. And, I cannot add the field in the database. I've researched regarding the checkbox losing the value when the page is changed and found all the code is either written in C# or they are using a gridview where I am using an aspxgridview or their gridview is built dynamically. I cannot seem to find anything with my scenario. Thanks for the input. - Tanya Hammil
In this case, would storing the Select value in a session variable work? You you keep track of the row index and checkbox value with a List(Of KeyValuePair(Of Integer, Boolean)). Then store that into the session with Session.Add("keyValuePair", CheckboxListValues). If you think that is viable, I can provide a full example - KRob
I think that may be something to try. What it is...there are several users, about 15, that can be creating work orders and a few could possibly be trying to create one at the same time. So...this may be a way to try it. If you could provide the example that would be great! Thank you! - Tanya Hammil
Multiple users will not be an issue. Session state is per browser. Here is a working example of a gridview with checkboxes that retain their value when navigating to a different page, then returning to the gridview. fc.krob636.com/KeepSelectValue.zip - KRob

1 Answers

0
votes

Please see original post. I show the changes that I made there. I found the information at: https://www.devexpress.com/Support/Center/Question/Details/Q527992

Thank you again KRob!