直接绑定到数据库里的table的
后台代码:
MKP.MyCommon.SQLHelper sh = new MKP.MyCommon.SQLHelper(null);
DataTable dt=sh.GetDataTable("select Fi_id,Fs_pCompanyName,Fs_phone,Fs_email from TpmCompany");
dataGrid1.ItemsSource = dt.DefaultView;
前台代码:
Height="153" HorizontalAlignment="Left" Name="dataGrid1" VerticalAlignment="Top"
Width="449" SelectedCellsChanged="dataGrid1_SelectedCellsChanged">
dataGrid1.ItemsSource = dt.AsDataView();
dataGrid的AutoGenerateColumns属性必须为true
直接绑定到数据库里的table的
后台代码:
MKP.MyCommon.SQLHelper
sh
=
new
MKP.MyCommon.SQLHelper(null);
DataTable
dt=sh.GetDataTable("select
Fi_id,Fs_pCompanyName,Fs_phone,Fs_email
from
TpmCompany");
dataGrid1.ItemsSource
=
dt.DefaultView;
前台代码:
class="csharp"
name="code">AutoGenerateColumns="False"
Height="153"
HorizontalAlignment="Left"
Name="dataGrid1"
VerticalAlignment="Top"
Width="449"
SelectedCellsChanged="dataGrid1_SelectedCellsChanged">> Header="ID"
Binding="{Binding
Path=Fi_id}"/>Header="公司名称"
Binding="{Binding
Path=Fs_pCompanyName}"/>Binding="{Binding
Path=Fs_phone}"
Header="电话"
/>Binding="{Binding
Path=Fs_email}"
Header="Email">