我有以下网格
<asp:GridView ID="gvVegetationZone" runat="server" AutoGenerateColumns="False" Style="width: 100%"
ShowHeader="False" AllowSorting="false" OnRowEditing="gvVegetationZone_RowEdit"
DataKeyNames="VegetationZoneID" OnRowDataBound="gvVegetationZone_RowDataBound"
SkinID="gvGreyHead">
<Columns>
<asp:Label ID="lblRedFlagData" runat="server" Text='<%# Convert.ToBoolean(DataBinder.Eval(Container.DataItem, "RedFlag")) ? "Yes" : "No"%>' />
在我的代码背后我试图根据条件将值设置为特定列但不知道该怎么做,希望有人会在这里指导我。
Assessment.tblVegetationZoneRow[] VegetationZoneData
= (Assessment.tblVegetationZoneRow[])objAssessment.tblVegetationZone.Select("SaveType <> " + Convert.ToString((int)EnumCollection.SaveType.RemoveOnly));
if((sitecurrentscore <=34) && (VegetationZoneData[0].EECID >0 || VegetationZoneData[0].PercentageCleared >70))
{
gvVegetationZone.Columns[5].value = false;
}
gvVegetationZone.Columns[5].Visible = true;
this.gvVegetationZone.DataSource = VegetationZoneData;
this.gvVegetationZone.DataBind();
到目前为止我不知道如何在绑定之前设置值,我试着这样但没有运气
顺便说一下lblRedFlagData是我的gridview中的第[5]栏 gvVegetationZone.Columns [5] .value = false;
答案 0 :(得分:0)
USE rowdatabound
void gvVegetationZone_RowDataBound(object sender, GridViewRowEventArgs e)
{
if(e.Row.RowType == DataControlRowType.DataRow)
{
string cellVALUE = e.Row.Cells[1].Text;
switch(cellVALUE )
{
case :
e.Row.Cells[1].Text = "column value";
}
}
}