Ext.Net- 要想获得GirdPanel里选项的ID值(单选和多选的ID值)

  学了几个星期EXT.NET了,发现他学习起来还是很麻烦的,如果是学C#或者SQL语句这些吧,网上一百度就有一大堆的文章还有一些视频可以看,所以入门其实不难。但EXT.NET的学习更多的只能看官网的DEMO,一边摸索着学习。

  像今天这个例子,在GirdPanel的TopBar里的一个Button按扭里添加一个事件,想获得GirdPanel里的选项值,我折腾了一个多小时才找到结果,而结果只是添加多一句语句就OK了。

        <ext:Store ID="Store1" runat="server" OnRefreshData="Store1_RefreshData">
            <Reader>
                <ext:JsonReader IDProperty="id">
                    <Fields>
                        <ext:RecordField Name="id" />
                        <ext:RecordField Name="name" />
                        <ext:RecordField Name="ftype" />
                        <ext:RecordField Name="contents" />
                        <ext:RecordField Name="fcount" />
                        <ext:RecordField Name="stime" Type="Date" />
                        <ext:RecordField Name="etime" Type="Date" />
                        <ext:RecordField Name="state" />
                        <ext:RecordField Name="addtime" Type="Date" />
                        <ext:RecordField Name="edittime" Type="Date" />
                        <ext:RecordField Name="createname" />
                    </Fields>
                </ext:JsonReader>
            </Reader>
        </ext:Store>

        <ext:GridPanel ID="GridPanel1" runat="server" StoreID="Store1" Title="DataReader Grid"
            Width="700" Height="400">
    <ColumnModel ID="ColumnModel1" runat="server">
                <Columns>
                    <ext:Column Header="ID" DataIndex="id" />
                    <ext:Column Header="会议名称" DataIndex="name" />
                    <ext:Column Header="会议类型" DataIndex="ftype" />
                    <ext:Column Header="会议内容" DataIndex="contents" />
                    <ext:Column Header="会议人数" DataIndex="fcount" />
                    <ext:Column Header="开始时间" DataIndex="stime">
                        <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                    </ext:Column>
                    <ext:Column Header="结束时间" DataIndex="etime">
                        <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                    </ext:Column>
                    <ext:Column Header="会议状态" DataIndex="state" />
                    <ext:Column Header="添加时间" DataIndex="addtime">
                        <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                    </ext:Column>
                    <ext:Column Header="编辑时间" DataIndex="edittime">
                        <Renderer Fn="Ext.util.Format.dateRenderer('Y-m-d H:i')" />
                    </ext:Column>
                    <ext:Column Header="创建人" DataIndex="createname" />
                </Columns>
            </ColumnModel>
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
            </SelectionModel>
            <LoadMask ShowMask="true" />
            <BottomBar>
                <ext:PagingToolbar ID="PagingToolbar1" runat="server" PageSize="10" StoreID="Store1" />
            </BottomBar>
        </ext:GridPanel>


看上面的HTML代码, 要想获得GirdPanel里选项的ID值,第一个是要有<ext:JsonReader IDProperty="id">
第二个如果是单行选择要SingleSelect="true"才行。
            <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
            </SelectionModel>

后台的事件关于单行选择可以这样写
            int selId = Int32.Parse(RowSelectionModel1.SelectedRow.RecordID);
            X.Msg.Alert("xx", selId.ToString()).Show();
也可以这样写
    //RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
            //SelectedRow row = sm.SelectedRow;
            //X.Msg.Alert("提示", row.RecordID.ToString()).Show();


如果是多行选择要SingleSelect="false"
       <SelectionModel>
                <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="false" />
            </SelectionModel>
后台的事件关于多行选择可以这样写
            //RowSelectionModel sm = this.GridPanel1.SelectionModel.Primary as RowSelectionModel;
            //StringBuilder sb = new StringBuilder();
            //foreach (SelectedRow row in sm.SelectedRows)
            //{
            //    sb.AppendFormat("RecordID: {0}&nbsp;&nbsp;&nbsp;&nbsp;Row index: {1}<br/>", row.RecordID, row.RowIndex);
            ////}
            //X.Msg.Alert("提示", sb.ToString()).Show();

 

posted @ 2012-12-22 10:36  春天又来了  阅读(361)  评论(0编辑  收藏  举报