Wednesday, March 21, 2012

dropdownlist in a tabpanel to display data from previous tabpanel

Hello All,

I have a DropDownList in one of my tab panels. The data to this dropdown is provided by a datasource. The data to this datasource is filled in one of the other tab panels. Since the contents of the other tab panel are inside an update panel, a full postback doesnt take place and hence my dropdown does not show any data that was added in the previous tab(unless you do a refresh on the page). Can anyone help me solve this issue with any suggestions? (I tried using the OnPreRender of the dropdownlist to bind the datasource but still it wouldnt display the most recently added data)

Any help will be greatly appreciated.

Thanks,

Nicky

Hi Nicky, Can you provide a small sample to illustrate it?

Raymond Wen - MSFT:

Hi Nicky, Can you provide a small sample to illustrate it?

Hello Raymond,

Sure. Here are the two Tab Panels that I amtalking about. The 'DetailsView' with ID "SpecializationCodeView1" onthe first tab panel inserts data and the 'DropDown' with ID"DropDownList2" on the second tab panel should display the inserteddata.

I could not use the same DataSourceID for these twocontrols since I am using "<%# Bind("specializationCode") %>" forthe dropdown andby doing so it gives me an error "Functions like Eval(), Bind() etc. can be used only with databound objects" while inserting data.

Can you please help?

Thanks,

Nicky

<ajaxToolkit:TabPanel ID="TabPanel4" runat="server">
<HeaderTemplate>Specializations</HeaderTemplate>
<ContentTemplate>
<asp:UpdatePanel ID="SpecializationGridUpdatePanel" runat="server">
<ContentTemplate>
<asp:GridView ID="SpecializationGrid" runat="server"DataKeyNames="id" DataSourceID="SpecializationDataSource2"
GridLines="Horizontal" Width="314px">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="code" HeaderText="code" SortExpression="code" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SpecializationCodeView1" EventName="ModeChanged" />
</Triggers>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="SpecializationViewUpdatePanel" runat="server">
<ContentTemplate>
<asp:DetailsView ID="SpecializationCodeView1" runat="server" AutoGenerateRows="False"
CellPadding="3" DataKeyNames="id" DataSourceID="SpecializationDataSource2" DefaultMode="Insert">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="code" HeaderText="code" SortExpression="code" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</ajaxToolkit:TabPanel>

<ajaxToolkit:TabPanel ID="TabPanel5" runat="server" >
<HeaderTemplate>
Sub Specializations
</HeaderTemplate>
<ContentTemplate>
<br />
<asp:UpdatePanel ID="SubSpecializationGridUpdatePanel" runat="server">
<ContentTemplate>
<asp:GridView ID="SubSpecializationGrid"runat="server" DataKeyNames="id"DataSourceID="SubSpecializationDataSource"
GridLines="Horizontal">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" Visible="False" />
<asp:BoundField DataField="code" HeaderText="code" SortExpression="code" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
<asp:BoundFieldDataField="specializationCode" HeaderText="specializationCode"SortExpression="specializationCode" />
</Columns>
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="SubSpecializationsView" EventName="ModeChanged" />
</Triggers>
</asp:UpdatePanel>
<br />
<asp:UpdatePanel ID="SubSpecializationInsertUpdatePanel" runat="server" UpdateMode="Conditional">
<ContentTemplate>
<asp:DetailsView ID="SubSpecializationsView" runat="server" AutoGenerateRows="False"
DataKeyNames="id" DataSourceID="SubSpecializationDataSource"
DefaultMode="Insert" GridLines="Horizontal" Height="50px" Width="125px">
<Fields>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="code" HeaderText="code" SortExpression="code" />
<asp:BoundField DataField="description" HeaderText="description" SortExpression="description" />
<asp:TemplateField HeaderText="specializationCode" SortExpression="specializationCode">
<EditItemTemplate>
<asp:Label ID="Label1"runat="server" Text='<%# Eval("specializationCode")%>'></asp:Label>
</EditItemTemplate>
<InsertItemTemplate>
<asp:DropDownList ID="DropDownList2" runat="server" DataSourceID="SpecializationDataSource"
DataTextField="description"DataValueField="code" SelectedValue='<%# Bind("specializationCode")%>'>
</asp:DropDownList>
</InsertItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1"runat="server" Text='<%# Bind("specializationCode")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>

</ajaxToolkit:TabPanel>

</ajaxToolkit:TabContainer>


I can't run the code directly.

But may be you can try to force the updatePanel that contains the DDL update in the ItemInserted event of the DetailsView?


protected void SpecializationCodeView1_ItemInserted(object sender, DetailsViewInsertedEventArgs e)
{
UpdatePanel up = tabContainer1.Tabs[1].Controls[0].FindControl("SubSpecializationInsertUpdatePanel") as UpdatePanel;
up.Update();
}


bvc xvbvx xvbcvcbcv cvb
bvc xvbvx xvbcvcbcv cvb

No comments:

Post a Comment