0
<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>


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. I just want to be able edit items on DataListOceny after clicking the "edit" button, please give me full code in code behind part... for edit DataListOceny .

1 Answers1

0

What you asking is same like the below thread.. You need to find the DataListOceny Control on each row of DataListDziennik to bind it

Using FindControl() to find control

https://msdn.microsoft.com/en-us/library/486wc64h%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396

And Here is some good example on the same

http://www.c-sharpcorner.com/UploadFile/rohatash/nested-datalist-in-Asp-Net/ http://surecode.net/DevCentre/NestedDataList/NestedDataList.aspx

Community
  • 1
  • 1
Moumit
  • 8,314
  • 9
  • 55
  • 59