Rebind Worksheet GridWeb
When you bind a worksheet to a dataset with the
Worksheets Designer in the IDE, a worksheet tag will be created in the APSX
file. It may look like this:
XML
<acw:Worksheet DataMember="Products" BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True" DataSource='<%# dataSet11 %>'>
When you call GridWeb1.DataBind() or WebWorksheet.DataBind(), the worksheet will be filled with the data in dataSet11.
Sometimes you may want to rebind the worksheet:
C#]
private void Button1_Click(object sender, System.EventArgs e)
{
<span class="n">GridWeb1</span><span class="p">.</span><span class="n">WorkSheets</span><span class="p">[</span><span class="m">0</span><span class="p">].</span><span class="n">Cells</span><span class="p">.</span><span class="n">Clear</span><span class="p">();</span>
<span class="c1">// Load data to the dataSet11.
LoadData(dataSet11);
<span class="n">GridWeb1</span><span class="p">.</span><span class="n">WorkSheets</span><span class="p">[</span><span class="m">0</span><span class="p">].</span><span class="n">DataBind</span><span class="p">();</span>
}
VB
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
<span class="n">GridWeb1</span><span class="p">.</span><span class="n">WorkSheets</span><span class="p">(</span><span class="m">0</span><span class="p">).</span><span class="n">Cells</span><span class="p">.</span><span class="n">Clear</span><span class="p">()</span>
<span class="err">'</span> <span class="n">Load</span> <span class="n">data</span> <span class="n">to</span> <span class="n">the</span> <span class="n">dataSet11</span><span class="p">.</span>
<span class="n">LoadData</span><span class="p">(</span><span class="n">dataSet11</span><span class="p">)</span>
<span class="n">GridWeb1</span><span class="p">.</span><span class="n">WorkSheets</span><span class="p">(</span><span class="m">0</span><span class="p">).</span><span class="n">DataBind</span><span class="p">()</span>
End Sub
The worksheet will always bind to dataSet11 even if you change the worksheet.DataSource property at runtime. This is because the sheet always uses the DataSource binding information in the worksheet’s tag in the ASPX file. To bind the sheet to another datasource at runtime, remove the datasource binding information in the worksheet tag in the ASPC file. Edit the tag to this:
XML
<acw:Worksheet BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True">
Specify the worksheet.DataSource and worksheet.DataMember properties before calling the DataBind method.