PDA

View Full Version : [CLOSED] asp:datalist inside ext window item.count always zero



Tonic
Jul 15, 2013, 10:55 AM
Hi,

I have asp:datalist inside a ext:window, i am binding the asp:datalist on click of button and showing the window at the same time which works fine.

But on click of another button which is in the window i count the items in datalist "Datalist.items.count" which is always Zero, however datalist is visible on the screen with data.

Please help in this , Below is my code

.Aspx
__________________________________________________ _________________________________________________


<ext:Window ID="winGetSplit" runat="server" Modal="true" Hidden="true" EnableViewState="true" Padding="5"
Title="split Process" Height="250" Width="450">
<Items>
<ext:TextField ID="tfCurrentCTC" runat="server" FieldLabel="Current CTC" Width="300"
Padding="5" ReadOnly="true">
</ext:TextField>
<ext:ComboBox ID="cbPayrollPolicy" runat="server" FieldLabel="Payroll Policy" Padding="5"
Width="300">
<Store>
<ext:Store ID="strPayrollPolicy" runat="server">
<Model>
<ext:Model ID="mdPayrollPolicy" runat="server">
<Fields>
<ext:ModelField Name="pk_CatalogMaster">
</ext:ModelField>
<ext:ModelField Name="catlShortDesc">
</ext:ModelField>
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
<ext:DateField ID="dfCompDate" runat="server" FieldLabel="Effective Date" Padding="5"></ext:DateField>
</Items>
<Content>
<table>
<tr>
<td>

<asp:DataList ID="dlSpitCTC" runat="server" EnableViewState="true">
<ItemTemplate>
<table>
<tr>
<td style="display: none">
</td>
<td style="padding: 3px">
<asp:Label ID="lblElementName" Visible="true" runat="server" Text='<%# Eval("Component code") %>'
Width="100px"></asp:Label>
</td>
<td style="padding: 3px">
<asp:TextBox ID="txtCompElement" runat="server" Text='<%# Eval("Amount") %>'></asp:TextBox>

</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>

</td>
</tr>
</table>
</Content>
<Buttons>
<ext:Button ID="btnSaveCTC" runat="server" Text="Save" Icon="Disk" OnDirectClick="btnSaveCTC_DirectClick">

</ext:Button>
<ext:Button ID="Button12" runat="server" Text="Cancel" Icon="Cancel">
</ext:Button>
</Buttons>
</ext:Window>


Binding DataList

__________________________________________________ __________________________________________________ ________


private void Split()
{
DataSet dssplit = fn.SplitCTC("576", tfCurrentCTC.Text);/// Function to bind data, you can use yours


if (X.IsAjaxRequest)
{

dlSpitCTC.DataSource = dssplit;
dlSpitCTC.DataBind();
dlSpitCTC.Update();
cbPayrollPolicy.Render();

winGetSplit.Render();
winGetSplit.Show();
}
}





btnSaveCTC_DirectClick event where i count the items

__________________________________________________ __________________________________________________ ___________




try
{

for (int i = 0; i < dlSpitCTC.Items.Count; i++)
{

////Some Code

}


}
catch (Exception ex)
{
X.Msg.Alert("Status", ex.Message, new JFunction { Fn = "" }).Show();
}

Daniil
Jul 15, 2013, 11:15 AM
Hi @Tonic,

A DataSource bound during one DirectEvent, doesn't persist during another one automatically. Neither Ext.NET or ASP.NET recreates it.

As a solution you could re-bind a DataSource during each request.

Tonic
Jul 15, 2013, 11:49 AM
Hi @Tonic,

A DataSource bound during one DirectEvent, doesn't persist during another one automatically. Neither Ext.NET or ASP.NET recreates it.

As a solution you could re-bind a DataSource during each request.



You mean to say that on btnSaveCTC_DirectClick i again bind the datalist

Daniil
Jul 15, 2013, 1:38 PM
Well, I think (but not 100% sure) yes, you could do it directly before you need to access a DataList's things.

Tonic
Jul 15, 2013, 1:45 PM
Well, I think (but not 100% sure) yes, you could do it directly before you need to access a DataList's things.

Daniil

Actually in my case there is textbox inside the datalist which user can manipulate , so if i rebind it the changes by user will be lost

Daniil
Jul 15, 2013, 1:49 PM
As another option you could try to enable ViewState.

1. Set up this:

<ext:ResourceManager runat="server" DisableViewState="false" />

2. Enable ViewState for a DirectEvent where you bind the data setting up ViewStateMode="Enabled" for a DirectEvent's config. For example, a Button's Click DirectEvent:

<Click OnEvent="TestDirectEventHandler" ViewStateMode="Enabled" />

By the way, do you really need to re-bind the DataList? What about to get the required data direct from the DataSource that you bind to the DataList?