如何在Gridview中绑定前编辑列值

本文关键字:编辑 绑定 Gridview | 更新日期: 2023-09-27 18:27:22

我有下面的网格,如

<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是我的网格视图中的列[5]gvVegetationZone.Columns[5].value=false;

如何在Gridview中绑定前编辑列值

使用行数据绑定

      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";
             }
    }

   }