我有一个与数据表绑定(bind)的 GridView 。我的问题是数据表的整数值为 1,2,3,4,5。
对于所有这些值,我想绑定(bind) A,B,C,D,E
分别在 GridView 中。我正在使用绑定(bind)字段。我不知道在哪里修改数据表中的数据?
最佳答案
将该列设为模板列并放置标签
<asp:TemplateField HeaderText="HeaderText">
<ItemTemplate>
<asp:Label ID="lbl" runat="server" ></asp:Label>
</ItemTemplate>
然后在 Gridview 的 RowDataBound
事件中执行此操作
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DataRow dr = ((DataRowView)e.Row.DataItem).Row;
if(dr["ColumnName"].ToString() == "1" )
{
((Label)e.Row.FindControl("lbl")).Text = "A";
}
else if(dr["ColumnName"].ToString() == "2" )
{
((Label)e.Row.FindControl("lbl")).Text = "B";
}
................
................
}
}
关于c# - 在 gridview 中进行数据绑定(bind)期间修改数据源行值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6276718/