10

用户控件,列表怎么传值

新增/修改页面上,点击[选择分类],弹出列表,选中其中一条,点击[OK]按钮,把这条数据的ID存到新增数据的Parentid里,同时在修改页面显示出title,
新增/修改页面代码:





/ext:Button
/ext:Label
/ext:Hidden

/ext:FieldContainer

var beforeCouChoose = function () {
//Ext.getCmp("hidCourseType").setValue(CourseType);
var dialog = Ext.getCmp("CouChooserDlg");

            if (dialog) {
                dialog.show();
                return false;
            }

            return true;
        };                                                              

     protected void ChooseCourse(object sender, DirectEventArgs e)
    {
        UserControlRenderer.Render(new UserControlRendererConfig { UserControlPath = "~/Components/CourseDialog.ascx", SingleControl = true });
    }                                                       

用户控件代码:<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="CourseDialog.ascx.cs" Inherits="WeChatManagementSystem.Components.CourseDialog" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>

var delmodel = function () { var node = App.CouChooserDlg.selModel.getSelection()[0]; alert(node); }

Height="600"
Width="900"
Cls="img-chooser-dlg"
Title="选择分类"
Layout="BorderLayout"
BodyBorder="0">

<Items>
    <ext:GridPanel
        ID="GridPanel1"
        runat="server"
        Title="Array Grid"
        Width="900">
        <Store>
            <ext:Store ID="Store1" runat="server" OnReadData="MyData_Refresh" PageSize="10">
                <Model>
                    <ext:Model runat="server">
                        <Fields>
                            <ext:ModelField Name="Id" Type="Int" />
                                    <ext:ModelField Name="Title" Type="String" />
                                    <ext:ModelField Name="CreatedBy" Type="String" />
                                    <ext:ModelField Name="CreatedDate" Type="Date" />
                                    <ext:ModelField Name="LastModifiedBy" Type="String" />
                                    <ext:ModelField Name="LastModifiedDate" Type="Date" />
                        </Fields>
                    </ext:Model>
                </Model>
            </ext:Store>
        </Store>
        <ColumnModel runat="server">
            <Columns>
                <ext:Column runat="server" Text="编号" DataIndex="Id" ID="Id" />
                <ext:Column runat="server" Text="标题" DataIndex="Title" Flex="1" ID="Title" />
                <ext:Column runat="server" Text="创建人" DataIndex="CreatedBy" ID="CreatedBy" />

                <ext:DateColumn runat="server" ID="CreatedDate" Text="创建日期" DataIndex="CreatedDate" Align="Center" Format="yyyy-MM-dd" />
                <ext:Column runat="server" ID="LastModifiedBy" Text="修改人" DataIndex="LastModifiedBy" />
                <ext:DateColumn runat="server" ID="LastModifiedDate" Text="修改" DataIndex="LastModifiedDate" Align="Center" Format="yyyy-MM-dd" />
            </Columns>
        </ColumnModel>
        <SelectionModel>
             <%--<ext:checkboxselectionmodel runat="server" id="delmodel"></ext:checkboxselectionmodel>--%>
            <ext:RowSelectionModel runat="server" Mode="Multi" />
        </SelectionModel>
        <View>
            <ext:GridView runat="server" StripeRows="true" />
        </View>
       <BottomBar>
            <ext:PagingToolbar ID="PagingToolbar1" runat="server">
                <Items>
                    <ext:Label ID="Label1" runat="server" Text="Page size:" />
                    <ext:ToolbarSpacer ID="ToolbarSpacer1" runat="server" Width="10" />
                    <ext:ComboBox ID="ComboBox1" runat="server" Width="80">
                        <Items>
                            <ext:ListItem Text="10" />
                            <ext:ListItem Text="20" />
                            <ext:ListItem Text="50" />
                            <ext:ListItem Text="100" />
                        </Items>
                        <SelectedItems>
                            <ext:ListItem Value="10" />
                        </SelectedItems>
                        <Listeners>
                            <Select Handler="#{GridPanel1}.store.pageSize = parseInt(this.getValue(), 10); #{GridPanel1}.store.load();" />
                        </Listeners>
                    </ext:ComboBox>
                </Items>
                <Plugins>
                    <ext:ProgressBarPager ID="ProgressBarPager1" runat="server"  EmptyMsg="没有可显示的记录" />
                </Plugins>
            </ext:PagingToolbar>
        </BottomBar>

    </ext:GridPanel>



   <ext:Hidden ID="hidType" runat="server"></ext:Hidden>
</Items>

<Buttons>
    <ext:Button runat="server" Text="OK">
        <Listeners>
             <Click Handler="var node = App.CouChooserDlg.selModel.getSelection()[0];

                if(node)
                {
                    App.hidParentId.setValue(node.id);
                    App.lblCourseTitle.setText(node.data.text);
                    var win = this.up('window')
                    win.hide();
                }

               " />
        </Listeners>
    </ext:Button>

    <ext:Button runat="server" Text="Cancel">
        <Listeners>
            <Click Handler="this.up('window').hide();" />
        </Listeners>
    </ext:Button>
</Buttons>

/ext:Window
.CS代码:

public partial class CourseDialog : System.Web.UI.UserControl
{
    CourseBLL cbll = new CourseBLL(HttpContext.Current.Session["Database"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        this.BindData();
        //this.Store1.DataSource = GetParentids();
    }
    protected void MyData_Refresh(object sender, StoreReadDataEventArgs e)
    {
        this.BindData();
    }
    private List<object> GetParentids()
    {

        var courselist = cbll.GetCourseByType(this.hidType.Text);

        List<object> data = new List<object>(courselist.Count);

        foreach (var course in courselist)
        {
            data.Add(new
            {
                id = course.Id,
                parentid = course.ParentID,
                title = course.Title,
                subtitle = course.SubTitle

            });
        }

        return data;
    }
    private void BindData()
    {

        Store store = this.GridPanel1.GetStore();
        var courselist = cbll.GetCourseByType(this.hidType.Text);
        store.DataSource = courselist;
        store.DataBind();
    }

    }

查看全部
Luze123654
Luze123654
2017/10/27 07:06
  • 弹窗
  • 控件
  • ascx
  • 点赞
  • 收藏
  • 回答
    私信

1个回复