简体   繁体   English

asp.net DataList内部的Datalist问题与C#解释

[英]asp.net DataList inside Datalist problems with C# interpretation

I need to use DataList inside another DataList . 我需要使用DataList另一个内部DataList It works fine for me, but when I'm trying to do something in code behind with this inside one it just doesn't exist for C#. 它对我来说很好,但是当我试图在其中使用这个内部代码时,它只是在C#中不存在。 Here is code: 这是代码:

...

<asp:DataList ID="DataListDziennik" runat="server"
    DataSourceID="SqlDataSourcePrzedmioty">
    <ItemTemplate>
        <asp:Label ID="LabelPrzedmiot" runat="server" Text='<%# Eval("przedmiot") %>' />

        ...

            <asp:DataList ID="DataListOceny" runat="server" 
                DataSourceID="SqlDataSourceOceny" 
                RepeatDirection="Horizontal" 
                OnItemCommand="DataListOceny_ItemCommandOceny"
                OnEditCommand="DataListOceny_EditCommandOceny">

                <EditItemTemplate>

                    <asp:TextBox ID="TextBoxOcena" runat="server" Text='<%# Bind("lista") %>' />
                    <td><asp:Button ID="ButtonZapisz" CommandName="Update" runat="server" Text="Zapisz" /></td>

                </EditItemTemplate>

                <ItemTemplate>

                    <asp:TextBox Width="20" ID="TextBoxOcena" ReadOnly="true" Text='<%# Eval("lista") %>' runat="server"></asp:TextBox>
                    <td><asp:Button ID="ButtonEdytuj" CommandName="Edit" runat="server" Text="Edytuj" /></td>

                </ItemTemplate>
            </asp:DataList>
        </td>
    </ItemTemplate>
</asp:DataList>

When I write this in code behind: 当我在代码后面写这个:

        protected void DataListOceny_EditCommand(object source, DataListCommandEventArgs e)
    {
        DataListOceny.EditItemIndex = e.Item.ItemIndex;

        DataListOceny.DataBind();
    }

...Visual Studio tells me that DataListOceny does not exist in current content . ... Visual Studio告诉我DataListOceny does not exist in current content I just want to be able edit items on DataListOceny after clicking the "edit" button, it can be placed anywhere on website. 我只是希望能够在单击“编辑”按钮后编辑DataListOceny项目,它可以放在网站上的任何位置。 Do you know any solution for this problem? 你知道这个问题的解决方案吗?

Because DataListOceny is a control inside of another control, you have to make a reference to it by doing something like: 因为DataListOceny是另一个控件内部的控件,所以你必须通过执行以下操作来引用它:

DataList DataListOceny = (DataList)e.Item.FindControl("DataListOceny");

Once you do that, you can use the DataListOceny variable. 完成后,您可以使用DataListOceny变量。 Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM