babafemi 0 Newbie Poster
Hello! i have two datalist controls, datalist1 which is the parent control and datalist2 which is the child control. They are both retrieving data from two related tables(primary/foreign). I want both datalists to respond to one edit, cancel, update and delete button, which are on the parent/outer datalist control. For now the delete button can delete data from both, but now i cant get the two datalists into edit mode from the edit button that is in the itemtemplate of the outer datalist. please who can help, i have done alli know to do, and even browsed. been on it for two weeks now. Thanks in advance.

    C#:

    protected void DataList1_ItemCommand(object source, DataListCommandEventArgs e)
            {
                foreach (DataListItem listitem in DataList1.Items)
                {
                    DList = listitem.ItemIndex;
                }

                if (e.CommandName == "Edit")
                {
                    DataList1.EditItemIndex = e.Item.ItemIndex;
                    var list = (DataList) DataList1. Items[DList].FindControl("DataList2");
                    list.EditItemIndex = e.Item.ItemIndex;
                    DataList1.DataBind();
                    list.DataBind();
                }
                if (e.CommandName == "Cancel")
                {
                    DataList1.SelectedIndex = e.Item.ItemIndex;
                    DataList1.EditItemIndex = -1;
                    DataList1.DataBind();
                }
                if (e.CommandName == "Update")
                {
                    //EditAchievementDataList.SelectedIndex = e.Item.ItemIndex;
                    //string username = User.Identity.Name;
                    //int userAchievementid = Convert.ToInt32(EditAchievementDataList.DataKeys[e.Item.ItemIndex]);
                    //TextBox achievement = (TextBox)e.Item.FindControl("AchievementLabel");
                    //AchievementManager.UpdateAchievement(username, achievement, userAchievementid);
                    //EditAchievementDataList.EditItemIndex = -1;
                    //EditAchievementDataList.DataBind();
                }

                if (e.CommandName == "Delete")
                {
                    DataList1.SelectedIndex = e.Item.ItemIndex;
                    string username = User.Identity.Name;
                    int doctorateid = Convert.ToInt32(DataList1.DataKeys[DataList1.SelectedIndex]);
                    DoctorateManager.DeleteDoctorate(username, doctorateid);
                    DataList1.DataBind();
                }
            }

    Aspx:

     <div id="" class="EditDiv">
                <asp:DataList ID="DataList1" runat="server" DataKeyField="DoctorateId"
                  OnItemCommand="DataList1_ItemCommand" EnableViewState="true" Width="455px"
                  DataSourceID="ObjectDataSource1">
                    <EditItemTemplate>
                        <div class="container">
                            <span id="objspan">DoctorateId</span>:<asp:TextBox ID="MyObj" CssClass="objective"
                                runat="server" Text='<%# Eval("DoctorateId") %>' TextMode="MultiLine" Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="hobbyspan">UserId</span>:<asp:TextBox ID="Hobby" runat="server" CssClass="objective"
                                Text='<%# Eval("UserId") %>' TextMode="MultiLine" Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="interestspan">Title</span>:<asp:TextBox ID="Interest" CssClass="objective"
                                runat="server" Text='<%# Eval("Title") %>' TextMode="MultiLine" Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="careerspan">Descipline</span>:<asp:TextBox ID="CareerObj" CssClass="objective"
                                runat="server" Text='<%# Eval("Descipline") %>' TextMode="MultiLine" Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="personalspan">StartMonth</span>:<asp:TextBox ID="PersoanlObj" CssClass="objective"
                                runat="server" Text='<%# Eval("StartMonth") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="Span1">StartYear</span>:<asp:TextBox ID="TextBox1" CssClass="objective"
                                runat="server" Text='<%# Eval("StartYear") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="Span2">EndMonth</span>:<asp:TextBox ID="TextBox2" CssClass="objective"
                                runat="server" Text='<%# Eval("EndMonth") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="Span3">Institution</span>:<asp:TextBox ID="TextBox3" CssClass="objective"
                                runat="server" Text='<%# Eval("Institution") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="Span4">Location</span>:<asp:TextBox ID="TextBox4" CssClass="objective"
                                runat="server" Text='<%# Eval("Location") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <div class="container">
                            <span id="Span5">Thesis</span>:<asp:TextBox ID="TextBox5" CssClass="objective"
                                runat="server" Text='<%# Eval("Thesis") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                        </div>
                        <asp:LinkButton ID="UpdateButton" runat="server" CommandName="Update" Style="padding-left: 154px;">Update</asp:LinkButton>
                        &nbsp;<asp:LinkButton ID="CancelButton" runat="server" CommandName="Cancel">Cancel</asp:LinkButton>
                    </EditItemTemplate>
                    <ItemTemplate>
                     <div class="container">
                       <div id="Div19" class="cont1">
                        DoctorateId:
                       </div>
                       <div id="Div20" class="cont2">
                        <asp:Label ID="DoctorateIdLabel" runat="server" Text='<%# Eval("DoctorateId") %>' />
                       </div>
                      </div>
                     <div class="container">
                       <div id="Div1" class="cont1">
                        UserId:
                       </div>
                       <div id="Div2" class="cont2">
                        <asp:Label ID="UserIdLabel" runat="server" Text='<%# Eval("UserId") %>' />
                       </div>
                     </div>
                     <div class="container">
                       <div id="Div3" class="cont1">
                        Title:
                       </div>
                       <div id="Div4" class="cont2">
                        <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' />
                       </div>
                     </div>
                     <div class="container">
                       <div id="Div5" class="cont1">
                        Descipline:
                       </div>
                       <div id="Div6" class="cont2">
                        <asp:Label ID="DesciplineLabel" runat="server" Text='<%# Eval("Descipline") %>' />
                        </div>
                     </div>
                     <div class="container">
                        <div id="Div7" class="cont1">
                         StartMonth:
                        </div>
                        <div id="Div8" class="cont2">
                         <asp:Label ID="StartMonthLabel" runat="server" Text='<%# Eval("StartMonth") %>' />
                        </div>
                     </div>
                     <div class="container">
                       <div id="Div9" class="cont1">
                        StartYear:
                       </div>
                       <div id="Div10" class="cont2">
                        <asp:Label ID="StartYearLabel" runat="server" Text='<%# Eval("StartYear") %>' />
                       </div>
                     </div>
                     <div class="container">
                       <div id="Div11" class="cont1">
                        EndMonth:
                       </div>
                       <div id="Div12" class="cont2">
                        <asp:Label ID="EndMonthLabel" runat="server" Text='<%# Eval("EndMonth") %>' />
                        </div>
                     </div>
                     <div class="container">
                       <div id="Div13" class="cont1">
                        EndYear:
                       </div>
                       <div id="Div14" class="cont2">
                        <asp:Label ID="EndYearLabel" runat="server" Text='<%# Eval("EndYear") %>' />
                       </div>
                     </div>
                     <div class="container">
                       <div id="Div15" class="cont1">
                        Institution:
                       </div>
                       <div id="Div16" class="cont2">
                        <asp:Label ID="InstitutionLabel" runat="server" Text='<%# Eval("Institution") %>' />
                        </div>
                     </div>
                     <div class="container">
                       <div id="Div17" class="cont1">
                        Location:
                       </div>
                       <div id="Div18" class="cont2">
                        <asp:Label ID="LocationLabel" runat="server" Text='<%# Eval("Location") %>' />
                        </div>
                     </div>
                     <div class="container">
                       <div id="Div21" class="cont1">
                        Thesis:
                       </div>
                       <div id="Div22" class="cont2">
                        <asp:Label ID="ThesisLabel" runat="server" Text='<%# Eval("Thesis") %>' />
                        </div>
                     </div>
                        <asp:DataList ID="DataList2" runat="server"
                            Width="455px" DataSourceID="FosObjectDataSource"
                            DataKeyField="DoctorateId"   
                            onitemcommand="DataList2_ItemCommand">
                         <EditItemTemplate>
                          <div class="container">
                            <span id="Span4">FeildofStudy</span>:<asp:TextBox ID="TextBox4" CssClass="objective"
                                runat="server" Text='<%# Bind("FeildofStudy") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                            </div>
                            <div class="container">
                             <span id="Span5">Feild</span>:<asp:TextBox ID="TextBox5" CssClass="objective"
                                runat="server" Text='<%# Bind("Feild") %>' TextMode="MultiLine"
                                Width="295px"></asp:TextBox>
                            </div>
                        </EditItemTemplate>
                        <ItemTemplate>
                         <div class="container">
                            <div id="Div22" class="cont6">
                              <asp:Label ID="Label1" runat="server" Text='<%# Eval("FeildofStudy") %>' />
                            </div>
                            <div id="Div21" class="cont5">
                              FeildofStudy:
                            </div>
                         </div>
                         <div class="container">
                            <div id="Div24" class="cont6">
                              <asp:Label ID="Label2" runat="server" Text='<%# Eval("Feild") %>' />
                            </div>
                            <div id="Div23" class="cont5">
                              Feild:
                            </div>
                         </div>
                         </ItemTemplate>
                        </asp:DataList>
                        <asp:ObjectDataSource ID="FosObjectDataSource" runat="server"
                            SelectMethod="SelectDocFos" TypeName="DataAccessLayer.DoctorateRepository"
                            onselecting="FosObjectDataSource_Selecting1">
                            <SelectParameters>
                                <asp:Parameter Name="username" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>
                        <div class="container">
                            <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                            <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                        </div>
                    </ItemTemplate>
                </asp:DataList>
                <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" OnSelecting="ObjectDataSource1_Selecting"
                    SelectMethod="FetchUserDoctorateDetails" TypeName="DataAccessLayer.DoctorateRepository">
                    <SelectParameters>
                        <asp:Parameter Name="username" Type="String" />
                    </SelectParameters>
                </asp:ObjectDataSource>
                <br />
            </div>
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.