1

似乎 CheckBoxField 不会接受 ID 属性,所以我不能直接在代码隐藏文件中调用组件。

<asp:DetailsView ID="dv" runat="server" AutoGenerateRows="False" 
    DataKeyNames="ID" DataSourceID="ds" DefaultMode="Insert" 
    OnItemInserting="dv_ItemInserting" OnItemInserted="dv_ItemInserted"
    OnItemUpdated="dv_ItemUpdated" OnItemCommand="dv_ItemCommand" 
    EnableModelValidation="True">
    <Fields>
        <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="false" ReadOnly="True" SortExpression="ID" />
        <asp:CheckBoxField ID="chkMidmarket" DataField="Midmarket_Flag" HeaderText="Midmarket" SortExpression="Midmarket_Flag" runat="server" />
        ...
    </Fields>
</asp:DetailsView>

我将如何检查文件隐藏代码中的复选框?

4

2 回答 2

2

In syour design view go to gridview edit columns and select the column and click convert to template field

    <asp:TemplateField HeaderText="Midmarket" SortExpression="Midmarket_Flag">
        <ItemTemplate>
            <asp:CheckBox ID="CheckBox1" runat="server" OnCheckedChanged ="CheckBox_CheckedChanged"
                Checked='<%# Bind("Midmarket_Flag") %>' Enabled="false" />
        </ItemTemplate>
    </asp:TemplateField>

Now you can add click event as above and your event something like below

protected void CheckBox_CheckedChanged(object sender, EventArgs e)
{
    try
    {
        CheckBox cb = sender as CheckBox;
        GridViewRow gr = cb.Parent.Parent as GridViewRow;
        string key = GridView1.DataKeys[gr.DataItemIndex].Value.ToString();
    }
    catch (Exception exc)
    {
    }
}
于 2013-05-17T15:51:25.887 回答
1

利用

<asp:CheckBox ID="youid" runat="server" />

这样您就可以从后面的代码中访问它

youid.Checked = true;
于 2013-05-17T15:34:33.453 回答