【发布时间】:2017-12-07 18:26:42
【问题描述】:
我在 Editable gridView 中有一个简单的复选框:
<asp:TemplateField HeaderText="Editable">
<ItemTemplate>
<asp:Label runat="server" Text="<%# Item.IsEditable %>" />
</ItemTemplate>
<EditItemTemplate>
<asp:CheckBox ID="CheckBoxEditable " runat="server" Text="Editable"></asp:CheckBox>
</EditItemTemplate>
</asp:TemplateField>
当我单击该行中的编辑按钮时,如果值为 true,我希望复选框已被选中。 (IsEditable 是一个布尔值) 文本字段很简单,因为我在 EditItemTemplate 中的 Text 属性上有一个 BindItem。但是checkBox或者dropdownlist就不一样了
网格视图
我使用 UpdateItem 方法来更新数据库中的数据。我尝试了一个小条件来检查我的复选框,但它不起作用。
public void GridViewRisquesAggravants_UpdateItem(IndexViewModel item)
{
try
{
if (ModelState.IsValid)
{
CheckBox chbEdit = (CheckBox)GridView.Rows[this.GridView.EditIndex].FindControl("CheckBoxEditable")
if (item.IsEditable)
chbEdit.Checked = true;
new TypeService().Update(new Type
{
IsEditable = item.IsEditable,
});
this.GridView.DataBind();
}
}
catch
{
throw;
}
}
这是有道理的,因为我没有在正确的函数中声明它。但我的网络表单中只有 3 个方法。
SelectMethod="GridView_GetData"
UpdateMethod="GridView_UpdateItem"
DeleteMethod="GridView_DeleteItem"
我在哪里可以做到这一点? (而且我对 dropdownList 上的数据也有同样的问题。我不知道在编辑过程中我在哪里恢复当前值)
提前致谢 (对不起,我是网络表单的初学者,我的英语不是很完美)
艾薇
【问题讨论】:
标签: c# asp.net gridview checkbox webforms