[英]how to set column in GridView to default value?
我在GridView中有一列稱為Qty Advised,該列需要默認為1。但是每次GridView加載時,它在該列中顯示0。 我將數據庫中的默認值設置為1並設置SerNo.QtyAdvised = 1;
在ItemDataBound
函數中,但仍顯示0。
有沒有辦法在這里設置默認值?
<asp:BoundField DataField="QtyAdvised" HeaderText="Qty Advised" ></asp:BoundField>
我不明白它如何持續顯示0 GridView是動態創建的。
可能是您需要使用DataColumn.DefaultValue
屬性。
創建新行時,它將設置列的默認值。
要么
或者,在rowdatabound上,您可以設置列默認值
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//Checking the RowType of the Row
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = "1"; // Use your column index here
}
}
通過在數據庫代碼中設置默認值來工作
public int _QtyAdvised = 1;
public int QtyAdvised
{
get { return _QtyAdvised; }
set { _QtyAdvised = value; }
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.