views:

90

answers:

2

I have a Standard .net 2.0 data grid which uses a XMLDatasource. The datasource is set dynamically by passing in XML string to the "Data" property of the XMLdatasource on a button click event.

This workd fine the first time around but not on subsequent button clicks.

i.e. eventhough the xml passed in changes the grid only diplays the initial output.

Is there something i need to do in order to make sure the grid refreshes to show the correct values??

current code

aspx grid code

<asp:GridView ID="GridView1" 
          Runat="server" 
          DataSourceID="XmlDataSource5" 
          AutoGenerateColumns="False" AllowPaging="True"
          style="width:100%; height:100%;" 
          AutoGenerateSelectButton="True" 
          EnableViewState="False">
    <SelectedRowStyle BackColor="Red" />
    <Columns>
       <asp:BoundField DataField="TYPE" HeaderText="TYPE" SortExpression="TYPE" />
       <asp:BoundField DataField="DESCRIPTION" HeaderText="DESCRIPTION" SortExpression="DESCRIPTION" />
    </Columns>
</asp:GridView>

vb.net code

Private Sub btnTest_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnTest.Click

    XmlDataSource5.Data = _testLib.GetGridXML(_Num)
    GridView1.DataBind()
End Sub

where _testLib.GetGridXML is a function that returns an XML string based on the _Num passed in.

A: 

You need to call DataBind on the grid to re-bind it to the updated values in the datasource

Macros
I tried adding GridView1.DataBind() just below where XmlDataSource5.Data property is being set.. still nothing...
eMTeeN
Can you post your code and markup?
Macros
question has been modified to include current code
eMTeeN
How is the data bound to the XmlDataSource originally before btnTest_Click is called?
Macros
The datasourceID property fo the grid is set to XMLDatasource5 in design time
eMTeeN
Sorry I meant the XmlDataSource itself - is that function the only one that specifies data or is there an initial Xml file assigned?
Macros
that function is the only one that specifies data. no initial XML file assigned. There is an XSLT template file assigned but that shouldnt affect this.
eMTeeN
It should work - can you post the aspx markup as well?
Macros
Where is _Num being set? Are you sure that it isn't just returning the same Xml each time?
Macros
_Num is being set by a text box input, i have stepped through the code and can see the xml being passes through to the Data property in the datasource. furthermore if the xml is not coming through the grid wont be populated in the 1st instance, but it is.
eMTeeN
Can't see anything wrong! If you put a breakpoint on the GridView1.DataBind() line, do you get the expected value for _num, is it different each time? Is the breakpoint only hit once per button click?
Macros
see my answer below.... thanks for your help!
eMTeeN
A: 

The problem was to do with the setup of the datasource itself and not the Gridview!

In order to make it refresh i needed to set the "EnableCaching" property in the XMLDatasource to "False" (it is set to "True" as default).

The grid now refreshes fine even without calling the Gridview.DataBind method.

Thanks for your time and help Macros!

eMTeeN
Good find - glad you fixed it!
Macros