Reputation: 35
i have an issue with a client project.
I have a ListView (lv1) of projects which is populated by a ObjectDataSource. I need to code a nested List (lv2) when you click on a button in a row of lv1, the button event should fetch the data then populate lv2. problem is i have tried with a nested ListView but lv2 is not populated onclick.
<asp:ListView id="lv1" runat="server" DataSourceID="foo_ods" OnItemCommand="ListV_Proj_ItemCommand">
<LayoutTemplate>
<table>
<thead>
<tr>
<th>Someheader</th>
</tr>
</thead>
<tr id="itemPlaceholder" runat="server" />
</table>
</LayoutTemplate>
<ItemTemplate>
<tr>
<td><asp:Button ID="btn_GetSubProj" Text="+" runat="server" CommandArgument='<%# Eval("Master") %>' CommandName="select" /></td>
<td>data for lv1</td>
</tr>
<tr>
<td>
<asp:ListView id="lv2" runat="server">
<ItemTemplate>some data</ItemTemplate>
</asp:ListView>
</td>
</tr>
</ItemTemplate>
</asp:ListView>
Codebehind
protected void ListV_Proj_ItemCommand(object sender, ListViewCommandEventArgs e)
{
DataTable subProTable = uWeb.Data.Project.List_Test(e.CommandArgument.ToString());
ListView subListV = (ListView)e.Item.FindControl("lv2");
subListV.DataSource = subProTable;
subListV.DataBind();
}
This is the basic structure of the code. Im not sure if it is the right approach. So in short.:
1) Can it be done with a nested ListView ? if yes How and what am i doing wrong? 2) is there a better way of doing it? only static is the objectdatasource AND the sub lines should only be fetched at button click(so not on lv1 binding).
Result should be a list that you can click a row it then shows the subrows. And because of the amount of data, the sublines(which are identical to the maste rlines in structure) should not be fetched from the db until the button is clicked.
I'm abit stressed so sorry if this post is messy. Feel free to tell me if i need to elaborate.
Upvotes: 1
Views: 359
Reputation: 35514
Try it without the CommandName
on the button. Without it everything works. But with it you get the error "he ListView 'lv1' raised event SelectedIndexChanging which wasn't handled". Names like 'select'. 'delete', 'update' etc are reserved for the OnCommands
<asp:Button ID="btn_GetSubProj" Text="+" runat="server" CommandArgument='<%# Eval("Master") %>' />
Upvotes: 1