重新绑定工作表 GridWeb
当您将工作表绑定到数据集时
IDE 中的工作表设计器,将在 APSX 中创建一个工作表标签
文件。它可能看起来像这样:
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">WebWorksheets</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">WebWorksheets</span><span class="p">[</span><span class="m">0</span><span class="p">].</span><span class="n">DataBind</span><span class="p">();</span>
}
虚拟机
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">WebWorksheets</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">WebWorksheets</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
即使您在运行时更改了 worksheet.DataSource 属性,工作表也将始终绑定到 dataSet11。这是因为工作表始终使用 ASPX 文件中工作表标记中的 DataSource 绑定信息。要在运行时将工作表绑定到另一个数据源,请删除 ASPC 文件中工作表标记中的数据源绑定信息。将标签编辑为:
XML
<acw:Worksheet BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True">
在调用 DataBind 方法之前指定 worksheet.DataSource 和 worksheet.DataMember 属性。