代码之家  ›  专栏  ›  技术社区  ›  Developer

如果不选择,如何将单选按钮切换为“是”或“否”

  •  0
  • Developer  · 技术社区  · 14 年前

    我写的条件是:

    if (dt > 0)
    {
       objinvoice.editInvoice(strInvoice, strRenew, strExpiry);
       GridView1.EditIndex = -1;
       bindGrid();
    }
    

    我将在GridView中有一个单选按钮,如果该单选按钮最初设置为false,并且如果条件为true,我希望将其设置为true….

    1 回复  |  直到 14 年前
        1
  •  1
  •   Kadir    14 年前

    您可以在GridView ItemDataBound事件中执行此操作。 您可以检查条件并更改单选按钮状态。

    GridView项数据绑定示例:

    private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
    if(e.Item.ItemType==System.Web.UI.WebControls.ListItemType.EditItem)
    
    RadioButton rBtnTest = e.Item.FindControl("radiobutton id") as RadioButton;
    // Check condition and if it's true
    if(your_condition == true)
     rBtnTest.Checked = true;
    else
     rBtnTest.Checked = false;
    }