PDA

View Full Version : [CLOSED] GridPanel SelectionModel



Timothy
Sep 25, 2008, 10:40 AM
Hello,

Perhaps you can help me out with the following 2 problems I'm encountering:

1. The CheckboxSelectionModel.SelectedID / SelectedIndex does not appear to be working i nthe example below.

2. When I select a record using the CheckboxSelectionModel and switch my view by hitting "Switch to View 2" and switch back by clicking "Switch to View 1" my selection is lost in the postback.

Example.aspx:


<%@ Page Language="C#" %>
<%@ Register Assembly="Coolite.Ext.Web" Namespace="Coolite.Ext.Web" TagPrefix="ext" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
protected void Page_Load(object sender, EventArgs e)
{
Permissions.DataSource = new object[] {
new object[] { 1, "Permission", "Permission 1" },
new object[] { 2, "Permission", "Permission 2" },
new object[] { 3, "Permission", "Permission 3" },
new object[] { 4, "Permission", "Permission 4" },
new object[] { 5, "Permission", "Permission 5" },
new object[] { 6, "Permission", "Permission 6" }
};
Permissions.DataBind();

if (!IsPostBack)
{
PermissionSelection.SelectedID = "1";
}
}
protected void Button1_Click(object sender, EventArgs e)
{
MultiView.SetActiveView(View2);
}
protected void Button2_Click(object sender, EventArgs e)
{
MultiView.SetActiveView(View1);
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title>Example</title>
</head>
<body>
<p><a href="Example.aspx">Reload</a></p>
<form id="form1" runat="server">
<ext:ScriptManager ID="ScriptManager1" runat="server" />
<ext:Store ID="Permissions"
runat="server"
AutoLoad="True"
GroupField="GroupingName">
<Reader>
<ext:ArrayReader ReaderID="PermissionId">
<Fields>
<ext:RecordField Name="PermissionId" />
<ext:RecordField Name="GroupingName" />
<ext:RecordField Name="DisplayName" />
</Fields>
</ext:ArrayReader>
</Reader>
<SortInfo Field="DisplayName" />
</ext:Store>
<asp:MultiView ID="MultiView" runat="server" ActiveViewIndex="0">
<asp:View ID="View1" runat="server">
<ext:GridPanel ID="GridPanel"
runat="server"
StoreID="Permissions"
AutoExpandColumn="DisplayName"
AutoHeight="True"
StripeRows="True"
Width="300">
<ColumnModel>
<Columns>
<ext:Column ColumnID="GroupingName" DataIndex="GroupingName" Header="Group" />
<ext:Column ColumnID="DisplayName" DataIndex="DisplayName" Header="Permission" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:CheckboxSelectionModel ID="PermissionSelection" runat="server" />
</SelectionModel>
</ext:GridPanel>
<ext:Button ID="Button1" runat="server" AutoPostBack="True" &#111;nclick="Button1_Click" Text="Switch to View 2" />
</asp:View>
<asp:View ID="View2" runat="server">
<ext:Button ID="Button2" runat="server" AutoPostBack="True" &#111;nclick="Button2_Click" Text="Switch to View 1" />
</asp:View>
</asp:MultiView>
</form>
</body>
</html>


Cheers,
Timothy

Vladimir
Sep 25, 2008, 2:31 PM
Hi Timothy,

1. The SelectedID and SelectedIndex works only if set Single mode for a selection model otherwise it ignores
2. Yes, there is a problem with MultiView because the selection doesn't saving to the ViewState. I'll fix it and post reply

Timothy
Sep 25, 2008, 2:37 PM
Hello vlad,

1. Oops you caught me, sorry I forgot that property...
2. You're awesome!

Cheers,
Timothy

geoffrey.mcgill
Sep 25, 2008, 5:15 PM
Hi Timothy and others...

We renamed to the .SelectedID property to .SelectedRecordID. This change keeps the naming convention of the "id" properties consistent within the SelectionModel and Reader classes.

Example


RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
sm.SelectedRecordID = "8";
The .SelectedRecordID and .SelectedIndex properties are only applicable when using SingleSelect="true" in the <ext:RowSelectionModel>.

Example


<ext:GridPanel>
....
<SelectionModel>
<ext:RowSelectionModel runat="server" SingleSelect="true" />
</SelectionModel>
</ext:GridPanel>

Timothy
Sep 25, 2008, 6:22 PM
Great, thanks for the pointer.

Does this also mean that the post back issue is resolved in my original request?

Cheers,
Timothy

Vladimir
Sep 25, 2008, 7:23 PM
Hi Timothy,

the fix in the SVN

Timothy
Sep 25, 2008, 7:26 PM
Awesome vlad ;)