Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/35.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将复选框绑定到数据库中的位字段(AJAX)_C#_Asp.net_Ajax_Gridview_Checkbox - Fatal编程技术网

C# 将复选框绑定到数据库中的位字段(AJAX)

C# 将复选框绑定到数据库中的位字段(AJAX),c#,asp.net,ajax,gridview,checkbox,C#,Asp.net,Ajax,Gridview,Checkbox,我有一个复选框,如果我的gridview中的条目已被“处理”(处理意味着用户已对其进行了检查),我想在其中加载一个复选框。我认为最好的方法是为每一行创建一个名为processed的字段,并在该行中包含一个复选框。当用户检查它时,我希望它在数据库中存储1。另外,当它加载时,我希望复选框加载一个复选框,这取决于数据库中的该字段。我真的很难弄清楚如何将这两个东西绑定在一起……我已经研究了语法,但我不能完全说出到底发生了什么。我也尝试过它,但它似乎没有存储信息——因此,我认为我的OnCheckedCha

我有一个复选框,如果我的gridview中的条目已被“处理”(处理意味着用户已对其进行了检查),我想在其中加载一个复选框。我认为最好的方法是为每一行创建一个名为processed的字段,并在该行中包含一个复选框。当用户检查它时,我希望它在数据库中存储1。另外,当它加载时,我希望复选框加载一个复选框,这取决于数据库中的该字段。我真的很难弄清楚如何将这两个东西绑定在一起……我已经研究了语法,但我不能完全说出到底发生了什么。我也尝试过它,但它似乎没有存储信息——因此,我认为我的OnCheckedChanged事件不能正常工作或根本不能工作。有什么建议吗

CS

public分部类vieworders:System.Web.UI.Page
{
私有字符串orderByString;
私有字符串字段字符串;
私有字符串地址;
私有DataGrid DataGrid=新DataGrid();
受保护的无效页面加载(对象发送方、事件参数e)
{
orderByString=orderByList.SelectedItem.Value;
fieldString=searchTextBox.Text;
string sqlStatement=“从SecureOrders中选择fName、lName、zip、email、cwaSource、price、length,其中fName类似“%”+fieldString+“%”或lName类似“%”+fieldString+“%”或zip类似“%”+fieldString+“%”或zip类似“%”+fieldString+“%”或电子邮件类似“%”+fieldString+“%”或cwaSource类似“%”+fieldString+“%”或长度类似“%””+fieldString+“%”或类似“%”+fieldString+“%”的价格,按“+orderByString”排序;
////////////////////////////
connectionString=rootWebConfig.connectionString.connectionString[“secureodb”];
//试验
对于(int i=0;i
ASPX


名字
姓
陈述
邮政编码
来源
加入日期

您可以像

 <ItemTemplate>
   <asp:CheckBox ID="CheckBoxProcess" OnCheckedChanged="CheckBoxProcess_CheckedChanged"  
             Checked='<%# Eval("FieldName") %>'  AutoPostBack="true" runat="server" Enabled="true" />
    </ItemTemplate>

对于“FieldName”,我如何设置它?我必须设置某种参数吗?您没有将数据源绑定到GridView吗?您的DataSource FieldName.it正在CS文件中绑定-我可以向您展示-我将更新代码
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="vieworders.aspx.cs" Inherits="Cabot3.custserv.vieworders" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID = "ScriptManager" runat="server" />
    <div>
        <div>
            <asp:Label runat="server" id = "orderByLabel" Text = "Order By: " />


            <asp:DropDownList runat="server" ID="orderByList" AutoPostBack="true">
                <asp:ListItem Value="fName" Selected="True">First Name</asp:ListItem>
                <asp:ListItem Value="lName">Last Name</asp:ListItem>
                <asp:ListItem Value="state">State</asp:ListItem>
                <asp:ListItem Value="zip">Zip Code</asp:ListItem>
                <asp:ListItem Value="cwaSource">Source</asp:ListItem>
                <asp:ListItem Value="cwaJoined">Date Joined</asp:ListItem>
            </asp:DropDownList>
        </div>
        <div>
            <asp:Label runat="server" ID="searchLabel" Text="Search For: " />
            <asp:TextBox ID="searchTextBox" runat="server" Columns="30" />
            <asp:Button ID="searchButton" runat="server" Text="Search" />
        </div>
    <div>
    <asp:UpdatePanel ID = "up" runat="server">



        <ContentTemplate>
        <div style= "overflow:auto; height:150px; width:700px">
        <asp:GridView ID="DefaultGrid" runat = "server" DataKeyNames = "fName, lName, zip"
        onselectedindexchanged = "DefaultGrid_SelectedIndexChanged"
        autogenerateselectbutton = "true"
        selectedindex="0">
        <SelectedRowStyle BackColor="Azure"
        forecolor="Black"
        font-bold="true" />
        <Columns>
        <asp:TemplateField HeaderText="Processed">
                    <ItemTemplate>
                        <asp:CheckBox ID="CheckBoxProcess" OnCheckedChanged="CheckBoxProcess_CheckedChanged"  AutoPostBack="true" runat="server" Enabled="true" />
                    </ItemTemplate>
                </asp:TemplateField>
        </Columns>
        </asp:GridView>
        </div>
        <asp:TextBox ID="OrderBrowser" columns="70" Rows="14" runat="server" Wrap="false" TextMode="MultiLine" ReadOnly = "true">
        </asp:TextBox>
        </ContentTemplate>
        </asp:UpdatePanel>



    </div>
    </form>
</body>
</html>
 <ItemTemplate>
   <asp:CheckBox ID="CheckBoxProcess" OnCheckedChanged="CheckBoxProcess_CheckedChanged"  
             Checked='<%# Eval("FieldName") %>'  AutoPostBack="true" runat="server" Enabled="true" />
    </ItemTemplate>
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
    if (e.CommandName == "")
    {

    }
}