2 回答

TA貢獻1802條經驗 獲得超10個贊
由于ds.Tables[0]
包含DataTable
對象,您可以使用DataRow.Field<T>()
擴展方法從指定的列名中查找值,將值替換為SetField()
然后重新綁定對網格數據源的更改:
foreach (DataRow dr in ds.Tables[0].Rows)
{
string oldValue = dr.Field<string>("ColumnName");
// check if the column has value
if (!string.IsNullOrEmpty(oldValue))
{
dr.SetField("ColumnName", value.ToString());
}
else
{
// do something else
}
}
ds.Tables[0].AcceptChanges();
// rebind the data source here
請注意,DataRow.Field<T>將值轉換為由Ttype 參數指定的類型,因此以下 if 條件使用 check againstnull或空字符串而不是DBNull.Value.

TA貢獻1820條經驗 獲得超9個贊
首先,bind您的grid view并添加OnRowDataBound喜歡
<asp:GridView ID="GridView1" runat="server" OnRowDataBound = "OnRowDataBound">
RowDataBound事件是triggered for each GridView RowRowGridView綁定到數據的時間。然后在您的OnRowDataBound事件代碼中
protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
column1 = e.Row.Cells[1].Text;
//here you can give the column no that you want get like e.Row.Cells[1]
e.Row.Cells[1].Text="test";
//you can set what you want like this
}
}
- 2 回答
- 0 關注
- 136 瀏覽
添加回答
舉報