重新绑定工作表 GridWeb
当您使用 IDE 中的 Worksheets Designer 将工作表绑定到数据集时,将在 APSX 中创建一个工作表标记。
文件。它可能看起来像这样:
XML
XML
<acw:Worksheet DataMember="Products" BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True" DataSource='<%# dataSet11 %>'>
当你调用 GridWeb1.DataBind() 或 WebWorksheet.DataBind() 时,工作表将被数据集 dataSet11 填充。
有时您可能想重新绑定工作表:
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
即使在运行时更改工作表.DataSource 属性,工作表始终会绑定到 dataSet11,这是因为工作表始终使用 ASPX 文件中工作表标记中的 DataSource 绑定信息。要在运行时将工作表绑定到另一个数据源,请移除 ASPC 文件中工作表标记中的数据源绑定信息。将标记编辑为如下内容:
XML
<acw:Worksheet BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True">
在调用 DataBind 方法之前,指定工作表的 DataSource 和 DataMember 属性。