主题:Datagrid里的ItemTemplate(label)抓不到值
dear all
asp.net版本为1.1
server为windows2003
我在datagrid里使用ItemTemplate放一个label
binddata后要把值塞入ItemTemplate里的label
但却没有动静
请问是那里出了问题
谢谢
default.aspx
<asp:datagrid id="dgFavorClass" runat="server" AutoGenerateColumns="False" DataKeyField="Fid">
<FooterStyle></FooterStyle>
<SelectedItemStyle></SelectedItemStyle>
<ItemStyle ></ItemStyle>
<HeaderStyle></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="序号">
<ItemTemplate>
<asp:Label id="lblSn" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="排序"></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="类别名称"></asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
default.aspx.cs
public string DSN = ConfigurationSettings.AppSettings["OLECN"];
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
public void BindGrid()
{
string SQL_DG = "SELECT * FROM FavorClass ORDER BY Sort ASC";
OleDbConnection myCn_DG = new OleDbConnection(DSN);
OleDbDataAdapter myCmd_DG = new OleDbDataAdapter(SQL_DG, myCn_DG);
DataSet ds = new DataSet();
myCmd_DG.Fill(ds, "FavorClass");
dgFavorClass.DataSource = ds.Tables["FavorClass"].DefaultView;
dgFavorClass.DataBind();
}
private void OnItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblSn = (Label)e.Item.FindControl("lblSn");
lblSn.Text = Convert.ToString("1");
}
}
asp.net版本为1.1
server为windows2003
我在datagrid里使用ItemTemplate放一个label
binddata后要把值塞入ItemTemplate里的label
但却没有动静
请问是那里出了问题
谢谢
default.aspx
<asp:datagrid id="dgFavorClass" runat="server" AutoGenerateColumns="False" DataKeyField="Fid">
<FooterStyle></FooterStyle>
<SelectedItemStyle></SelectedItemStyle>
<ItemStyle ></ItemStyle>
<HeaderStyle></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="序号">
<ItemTemplate>
<asp:Label id="lblSn" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="排序"></asp:TemplateColumn>
<asp:TemplateColumn HeaderText="类别名称"></asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Left" Mode="NumericPages"></PagerStyle>
</asp:datagrid>
default.aspx.cs
public string DSN = ConfigurationSettings.AppSettings["OLECN"];
private void Page_Load(object sender, System.EventArgs e)
{
if (!this.IsPostBack)
{
BindGrid();
}
}
public void BindGrid()
{
string SQL_DG = "SELECT * FROM FavorClass ORDER BY Sort ASC";
OleDbConnection myCn_DG = new OleDbConnection(DSN);
OleDbDataAdapter myCmd_DG = new OleDbDataAdapter(SQL_DG, myCn_DG);
DataSet ds = new DataSet();
myCmd_DG.Fill(ds, "FavorClass");
dgFavorClass.DataSource = ds.Tables["FavorClass"].DefaultView;
dgFavorClass.DataBind();
}
private void OnItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Label lblSn = (Label)e.Item.FindControl("lblSn");
lblSn.Text = Convert.ToString("1");
}
}