Återbind kalkylblad GridWeb
När du binder ett kalkylblad till en dataset med
Arbetsbladsdesignern i IDE:n skapas en arbetsbladsetikett 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 kalkylarket att fyllas med data i dataSet11.
Ibland kan du vilja ombinda kalkylarket:
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
Kalkylarket kommer alltid att binda till dataSet11 även om du ändrar worksheet.DataSource-egenskapen vid körning. Detta beror på att arket alltid använder bindningsinformationen för DataSource i taggen för kalkylarket i ASPX-filen. För att binda arket till en annan datakälla vid körning, ta bort bindningsinformationen för datakällan i arket i ASPC-filen. Redigera taggen till detta:
XML
<acw:Worksheet BindStartRow="2" Name="Products"
EnableCreateBindColumnHeader="True">
Ange worksheet.DataSource- och worksheet.DataMember-egenskaperna innan du anropar DataBind-metoden.