Återbind kalkylblad GridWeb
När du binder ett kalkylblad till en datauppsättning med
Kalkylbladsdesigner i IDE, en kalkylbladstagg kommer att skapas i APSX
fil. Det kan se ut så här:
XML
<acw:Worksheet DataMember="Products" BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True" DataSource='<%# dataSet11 %>'>
När du anropar GridWeb1.DataBind() eller WebWorksheet.DataBind(), kommer kalkylbladet att fyllas med data i dataSet11.
Ibland kanske du vill binda om arbetsbladet:
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>
}
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">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
Kalkylbladet kommer alltid att binda till dataSet11 även om du ändrar egenskapen workheet.DataSource vid körning. Detta beror på att arket alltid använder DataSource-bindningsinformationen i kalkylbladets tagg i ASPX-filen. Om du vill binda arket till en annan datakälla vid körning tar du bort datakällans bindningsinformation i kalkylbladstaggen i ASPC-filen. Redigera taggen till detta:
XML
<acw:Worksheet BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True">
Ange egenskaperna för arbetsblad.Datakälla och arbetsblad.DataMember innan du anropar DataBind-metoden.