Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

nested datalist control problem 1

Status
Not open for further replies.

vcllvc

Programmer
Jul 12, 2001
136
US
I have a nested Gridview within a Datalist. The Datalist consists of a linklist button for a membership number and the nested gridview display detail record of that member.

The problem is when i click on a linklist button all the gridviews within the datalist display the same record; not the one that refer to each datalist row.

Does anyone have the same problem and have any suggestions?

Thanks in advance
 
sound like your binding your main datalist incorrectly on click of your linkbutton

can you post your events so we can help more?
(just snippets, and please dont display passwords or confidential info!)

DataList databind
DataList edit item
gridview databind

html of your datalist
 
here is my ItemCommand event for datalist.

protected void dlMSDealer_ItemCommand(object source, DataListCommandEventArgs e) {

sqldsMSDealerDetail.SelectParameters["DealerCode"].DefaultValue = ((LinkButton) e.CommandSource).Text;
GridView gv = (GridView) e.Item.FindControl("gvDealerMSDetail");
gv.Visible = !gv.Visible;

}
 
this is the datalist

<asp:DataList ID="dlMSDealer" runat="server" CssClass="sam_blk10" DataSourceID="sqldsMSDealerCode"
OnItemCommand="dlMSDealer_ItemCommand">
<ItemTemplate>
&nbsp;<asp:LinkButton ID="lkbtnDealerCode" runat="server" OnClick="lkbtnDealerCode_Click"
Text='<%# Eval("DealerCode") %>'></asp:LinkButton>
<asp:GridView ID="gvDealerMSDetail" runat="server" AllowPaging="True" AllowSorting="True"
AutoGenerateColumns="False" CssClass="sam_blk10" DataKeyNames="ID" DataSourceID="sqldsMSDealerDetail">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True"
SortExpression="ID" />
<asp:BoundField DataField="DealerCode" HeaderText="DealerCode" SortExpression="DealerCode" />
<asp:BoundField DataField="CompanyCode" HeaderText="CompanyCode" SortExpression="CompanyCode" />
<asp:BoundField DataField="ManufSpecName" HeaderText="ManufSpecName" SortExpression="ManufSpecName" />
<asp:BoundField DataField="LastModifyDate" HeaderText="LastModifyDate" SortExpression="LastModifyDate" />
</Columns>
</asp:GridView>
<br />
<br />
</ItemTemplate>
<HeaderTemplate>
Dealer Code:
</HeaderTemplate>
</asp:DataList>
 
put your gridview in an EditItemTemplate of the DataList, then use the DataList OnEditCommand instead.


<asp:DataList onEditCommand=ProcedureNameHere
<ItemTemplate>
<asp:LinkButton ID="lkbtnDealerCode" runat="server" CommandName=Edit Text='<%# Eval("DealerCode") %>'></asp:LinkButton>
</ItemTemplate>
<EditItemTemplate>
<asp:GridView>
</EditItemTemplate>



 
oh, nice, thanks.
Then how can find the gridview control within the editcommand event, so that i can bind the grid to the datasource

 
similar to what you have...

void dlEdit(object sender, DataListCommandEventArgs e)
...
GridView gv = (GridView) e.Item.FindControl("gvDealerMSDetail");


e is now your Edit Item Template location
 
...scratch that...i have code (in vb) ill paste here in a sec...
 
Code:
    Sub dlEdit(ByVal sender As Object, ByVal e As DataListCommandEventArgs)
        dlSquawk.EditItemIndex = e.Item.ItemIndex
        BindSquadInfo()
        ShowTopicReplies()
    End Sub

    Sub ShowTopicReplies()
        Dim dg As DataList = CType(dlSquawk.Items(dlSquawk.EditItemIndex).FindControl("dgTopicReplies"), DataList)
        Dim objCon As New SqlConnection(conString)
        Dim objComm As New SqlCommand("sp_TopicReplies", objCon)
        objComm.CommandType = CommandType.StoredProcedure
        objComm.Parameters.Add("@tid", SqlDbType.Int, 4).Value = dlSquawk.DataKeys(dlSquawk.EditItemIndex)
        Dim da As New SqlDataAdapter(objComm)
        Dim ds As New DataSet()
        Try
            da.Fill(ds)
            If ds.Tables(0).Rows.Count > 0 Then
                dg.DataSource = ds.Tables(0)
                dg.DataBind()
            End If
        Catch ex As Exception

        Finally
            objCon.Close()
        End Try
    End Sub


here comes html...its large and nesting...
 
Code:
<asp:DataList ID="dlSquawk" runat="server" RepeatColumns="1" RepeatDirection="Vertical"
                                                Width="100%" OnItemDataBound="topic_idb" OnEditCommand="dlEdit" OnUpdateCommand="dlUpdate" OnCancelCommand="dlCancel"
                                                DataKeyField="topicID">
                                                <HeaderTemplate>
                                                    <table border="0" cellpadding="3" cellspacing="1" bgcolor="#c4c4c4" width="100%">
                                                        <tr>
                                                            <td style="font-size: 9pt; font-family: Arial; font-weight: bold" align="left">
                                                                <u>Squawk Box</u>
                                                            </td>
                                                            <td align="right">
                                                                <asp:LinkButton ID="lbNewTopic" runat="server" Text="New Topic" CssClass="hyper"
                                                                    OnClick="new_Topic" Visible="false" />
                                                            </td>
                                                        </tr>
                                                </HeaderTemplate>
                                                <ItemTemplate>
                                                    <tr>
                                                        <td class="dgPromo" align="left">
                                                            <b>
                                                                <%#DataBinder.Eval(Container.DataItem, "topicSubject")%>
                                                            </b>
                                                            <br />
                                                            By
                                                            <%#DataBinder.Eval(Container.DataItem, "clanName")%>
                                                            <br />
                                                            <%#DataBinder.Eval(Container.DataItem, "topicDate", "{0:d}")%>
                                                            - Replies (<%#DataBinder.Eval(Container.DataItem, "replies")%>)<br />
                                                            <asp:LinkButton ID="lbReplyTopic" runat="server" Text="View Replies" CssClass="dgPromo"
                                                                CommandName="Edit" />&nbsp;&nbsp;
                                                            <asp:LinkButton ID="lbDelTopic" runat="server" Text="Delete Topic" CssClass="dgPromo"
                                                                OnCommand="del_Topic" CommandName="Delete" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "topicID")%>' />
                                                        </td>
                                                        <td class="dg" valign="top" align="left">
                                                            <%#Replace(DataBinder.Eval(Container.DataItem, "topicDetail"), ControlChars.CrLf, "<br>")%>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td colspan=2>
                                                            <hr width=98% />
                                                        </td>
                                                    </tr>
                                                </ItemTemplate>
                                                <EditItemTemplate>
                                                    <tr>
                                                        <td class="dgPromo" align="left">
                                                            <b>
                                                                <%#DataBinder.Eval(Container.DataItem, "topicSubject")%>
                                                            </b>
                                                            <br />
                                                            By
                                                            <%#DataBinder.Eval(Container.DataItem, "clanName")%>
                                                            <br />
                                                            <%#DataBinder.Eval(Container.DataItem, "topicDate", "{0:d}")%>
                                                            - Replies (<%#DataBinder.Eval(Container.DataItem, "replies")%>)
                                                        </td>
                                                        <td class="dg" valign="top" align="left">
                                                            <%#Replace(DataBinder.Eval(Container.DataItem, "topicDetail"), ControlChars.CrLf, "<br>")%>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                        </td>
                                                        <td>
                                                            <asp:DataList ID="dgTopicReplies" runat="server" Width="100%" RepeatColumns="1" RepeatDirection="Vertical">
                                                                <HeaderTemplate>
                                                                    <table border="0" cellpadding="0" cellspacing="0" class="dgPromo" width="100%">
                                                                </HeaderTemplate>
                                                                <ItemTemplate>
                                                                    <tr>
                                                                        <td bgcolor="#d8d8d8" align="left">
                                                                            <b>
                                                                                <%#DataBinder.Eval(Container.DataItem, "clanName")%>
                                                                            </b>
                                                                        </td>
                                                                        <td align="left" bgcolor="#d8d8d8" width=90%>
                                                                            - <%#DataBinder.Eval(Container.DataItem, "replyDate", "{0:d}")%>
                                                                        </td>
                                                                    </tr>
                                                                    <tr>
                                                                        <td></td>
                                                                        <td valign=top align=left>                                                                            
                                                                            <%#Replace(DataBinder.Eval(Container.DataItem, "replyDetail"), ControlChars.CrLf, "<br>")%>
                                                                        </td>
                                                                    </tr>
                                                                </ItemTemplate>
                                                                <FooterTemplate>
                                                                    </table>
                                                                </FooterTemplate>
                                                            </asp:DataList>
                                                        </td>
                                                    </tr>
                                                    <tr>
                                                        <td>
                                                        </td>
                                                        <td align="left">
                                                            <asp:TextBox ID="tbReply" runat="server" Width="100%" Height="50" CssClass="labels" /><br />
                                                            <asp:LinkButton ID="lbCloseReply" runat="server" Text="Close" CssClass="dg" CommandName="Cancel" />&nbsp;&nbsp;
                                                            <asp:LinkButton ID="lblSave" runat="server" Text="Post Reply" CssClass="dg" CommandName="Update" />
                                                        </td>
                                                    </tr>
                                                </EditItemTemplate>
                                                <FooterTemplate>
                                                    </table>
                                                </FooterTemplate>
                                            </asp:DataList>
 
thank you very much.
it looks beautiful now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top