[英]Modify datasource row values during databind in gridview
我有一个与数据表绑定的网格视图。 我的问题是数据表的 integer 值为1,2,3,4,5.
对于所有这些值,我想分别在网格视图中绑定A,B,C,D,E
。 我正在使用绑定字段。 我不知道在哪里修改来自数据表的数据??
将该列设为模板列并放入 label
<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";
}
................
................
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.