Aug 08, 2011, 11:18 PM
[CLOSED] SelectionModel.SelectAll() Not Working As Expected
I have a page with a simple gridpanel. When the page first loads, I want all the rows in the grid to be pre-selected. In other words, I want the checkboxes to be defaulted to checked for each row.
When I click the submit button, I want to perform a simple check to see if the user has any rows selected. If the user didn't select any rows, I want to display a message box stating that the user must select at least one row.
What is happening in my code is:
1. The rows are not coming in checked when the page is loaded.
2. When the user clicks submit without selecting any rows, the warning message is not displayed. Also, as a weird side-effect, clicking the Submit button causes the all the rows to become checked. I do not understand this behavior.
Please take a look at my sample code and help me to understand what is going on.
Thanks.
When I click the submit button, I want to perform a simple check to see if the user has any rows selected. If the user didn't select any rows, I want to display a message box stating that the user must select at least one row.
What is happening in my code is:
1. The rows are not coming in checked when the page is loaded.
2. When the user clicks submit without selecting any rows, the warning message is not displayed. Also, as a weird side-effect, clicking the Submit button causes the all the rows to become checked. I do not understand this behavior.
Please take a look at my sample code and help me to understand what is going on.
Thanks.
<%@ Page Language="vb" AutoEventWireup="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim data As New List(Of Object)
With data
.Add(New With {.AccountID_in = 1, .DisplayName = "Indiana Jones", .AccountNumber_vc = "1232133", .AccountType_vc = "IRA", .MarketValue = 3122312.32})
End With
GoodAccountsStore.DataSource = data
GoodAccountsStore.DataBind()
GoodSelectionModel.SelectAll()
End Sub
Public Sub SubmitButton_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim count As Integer = 0
For Each row In CType(GoodAccountsGrid.SelectionModel.Primary, RowSelectionModel).SelectedRows
count += 1
Next
If count = 0 Then
Dim xConfig As New Ext.Net.MessageBoxConfig
With xConfig
.Title = "Account Selection Error"
.Message = "Please select at least one account."
.Buttons = Ext.Net.MessageBox.Button.OK
End With
Ext.Net.X.Msg.Show(xConfig)
Exit Sub
End If
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<ext:ResourceManager ID="ResourceManager1" runat="server" />
<div>
<ext:GridPanel ID="GoodAccountsGrid" Title="Accounts Eligible for Householding" runat="server"
Height="150" Collapsible="true" AutoExpandColumn="DisplayName">
<Store>
<ext:Store ID="GoodAccountsStore" runat="server">
<Reader>
<ext:JsonReader IDProperty="AccountID_in">
<Fields>
<ext:RecordField Name="AccountID_in">
</ext:RecordField>
<ext:RecordField Name="DisplayName" />
<ext:RecordField Name="AccountNumber_vc" />
<ext:RecordField Name="AccountType_vc" />
<ext:RecordField Name="MarketValue" Type="Float" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
</Store>
<ColumnModel ID="ColumnModel1" runat="server">
<Columns>
<ext:Column Header="Description" Width="160" DataIndex="DisplayName" />
<ext:Column Header="Account Number" Width="150" DataIndex="AccountNumber_vc" />
<ext:Column Header="Account Type" Width="150" DataIndex="AccountType_vc" />
<ext:Column Header="Market Value" Width="150" DataIndex="MarketValue">
<Renderer Format="UsMoney" />
</ext:Column>
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel ID="GoodSelectionModel" runat="server" />
</SelectionModel>
</ext:GridPanel>
<ext:Button runat="server" ID="SubmitButton" Text="Submit">
<DirectEvents>
<Click OnEvent="SubmitButton_Click" />
</DirectEvents>
</ext:Button>
</div>
</form>
</body>
</html>
Last edited by Daniil; Aug 15, 2011 at 3:58 PM.
Reason: [CLOSED]