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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DataList refresh after changing the DataSource 2

Status
Not open for further replies.

Otto

Programmer
Dec 31, 1998
224
HU
Hi!

On a button click I create a new DS and assign it to a DataList. The count of the asked rows are based on a textbox.
Code:
        XmlDataSource xds=new XmlDataSource();
        xds.Data=ws.QueryAsXML("select top "+TextBox1.Text+" ... ");
        xds.DataBind();
        DataList1.DataSource = xds;
        DataList1.DataBind();
But DL don't refresh. Always shows the first asked data values and the number of displayed rows are the same (the initial) as well.

I've tried to clear the controls, set DataSourceID instead of DS, GridView, Listview, disable the ViewState, etc. But the problem is the same.

Any help is greatly appreciated.
 
No. The Page_Load is empty. I assign the DS only on button click.
Here is the 'full' code:
Code:
<%@ Page Language="C#"%>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="ajaxToolkit" %>
<script language="C#" runat="server">
    protected void Button1_Click(object sender, EventArgs e)
    {
        GymePatikaKozpont.GymePatikaSvc.GymePatikaSvc ws = new GymePatikaKozpont.GymePatikaSvc.GymePatikaSvc();
        XmlDataSource xds=new XmlDataSource();
        xds.Data=ws.GetGymeQueryAsXML("select top "+kTextBox1.Text+" ... ");
        xds.DataBind();
        DataList1.Controls.Clear();
        DataList1.DataSource = xds;
        DataList1.DataBind();
        ws.Dispose();
    }
</script>
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>KezelÅ'k</title>
    <style type="text/css">
        #form1
        {
            width: 1000px;
        }
    </style>
</head>
<body>
    <form runat="server" style="width: 1000px">
    <asp:UpdateProgress ID="UpdateProgress1" runat="server">
        <ProgressTemplate>Dolgozom...
        </ProgressTemplate>
    </asp:UpdateProgress>
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
    <ajaxToolkit:TextBoxWatermarkExtender ID="TBWE2" runat="server"
    TargetControlID="kezelokodTextBox"
    WatermarkText="KezelÅ'kód?"
    WatermarkCssClass="watermarked" />
        <asp:Label ID="Message" ForeColor="Red" runat="server"/><br/>
        <table>
                <tr><td>KezelÅ'kód: <asp:TextBox ID="kTextBox" runat="server" /></td>
                <td>
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="KezelÅ'k" />
                    <asp:DataList ID="DataList1" runat="server" BorderColor="Black"
                        BorderWidth="1px" GridLines="Both" EnableViewState="False" DataKeyField="KEZELOKOD">
                        <ItemTemplate>
                            Kód: <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("KEZELOKOD") %>' EnableViewState="False" />
                            NÃcv: <asp:TextBox ID="nevTextBox" runat="server" Text='<%# Bind("NEV") %>' EnableViewState="False" />
                            Jelszó: <asp:TextBox ID="TextBox3" runat="server" Text='<%# Bind("KULCS") %>' EnableViewState="False" />
                        </ItemTemplate>
                    </asp:DataList>
                </td>
            </tr>
        </table>
    </ContentTemplate>
    </asp:UpdatePanel>
    </form>
</body>
</html>
 
Yes, of course I have tested it. The data provider web service working well. Both the data (if I change it from another application) and the number of rows are changed on click. But the date in the DataList remains unchanged.
I'm using VS2008...
 
As we don't have access to your methods that return the data, we have to assume that they may be part of the problem. For example, I can't replicate you problem in my simple test:
Code:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default1.aspx.vb" Inherits="Default1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]

<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml"[/URL] >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
        <asp:Button ID="Button1" runat="server" Text="Button" />
        <asp:DataList ID="DataList1" runat="server">
            <ItemTemplate>
                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Container.DataItem %>' />
            </ItemTemplate>
        </asp:DataList>
    </div>
    </form>
</body>
</html>
Code:
Partial Class Default1
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim a As New ArrayList
        For i As Integer = 0 To TextBox1.Text
            a.Add(i)
        Next
        DataList1.DataSource = a
        DataList1.DataBind()
    End Sub
End Class
So, I'd suggest doing the same thing as what I have done, and then place your calls into the simple test, one by one, until you find out where the problem is occurring.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I've done your test code. It worked.
I did a simple xml assign with 1 row and with 2 rows:
Code:
<items><item KEZELOKOD="1" NEV="AA" KULCS="A       "/></items>
and
<items><item KEZELOKOD="1" NEV="AA" KULCS="A       "/><item KEZELOKOD="5" NEV="AGI3" KULCS="AGI     "/></items>
It failed.
It got me to the solution:
Code:
XmlDataSource xds=new XmlDataSource();
[b]xds.EnableCaching=false;[/b]
xds.Data=
...

Thanks a lot!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top