.net,gridview.中的按纽问题!

来源:百度知道 编辑:UC知道 时间:2024/05/20 20:47:37
在GRIDVIEW中有一个按纽,当该行指定字段没有数据时,按纽显示为“登陆”;当该行指定字段有数据时,按纽显示为“修改”。
请高手帮忙,如何实现?
我只有一个按纽,而且是GRIDVIEW中的buttonfield,不是普通的button,主要我不明白怎么修改buttonfield的text ,请高手指点!

TableCell cell=row.Controls[1];
if(cell.Text==string.Empty)
{
btn.text="登陆";
}
else
{
btn.text="修改";
}
}

这个是OK的,我试过了!
前台:
<asp:GridView ID="gvTest" runat="server" OnRowDataBound="gvTest_RowDataBound">
<Columns>
<asp:ButtonField ButtonType="Button" Text="Modify" />
</Columns>
</asp:GridView>
后台:
protected void gvTest_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType ==DataControlRowType.DataRow)
{
Button o = (Button)e.Row.Cells[0].Controls[0];
o.Text = "Changed";
}
}
你可以通过判断更改Button内容

把你的buttonfield转换成TemplateField。
然后gridview的RowDataBound事件做处理
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e