首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

~GridView1中更新数据 CheckBox如何更新

2012-02-14 
救命啊~~~~~GridView1中更新数据 CheckBox怎么更新前台代码asp:GridViewID GridView1 runat server

救命啊~~~~~GridView1中更新数据 CheckBox怎么更新
前台代码
<asp:GridView   ID= "GridView1 "   runat= "server "   AllowPaging= "True "   AllowSorting= "True "
                AutoGenerateColumns= "False "   DataKeyNames= "登陆ID "
                GridLines= "None "   PageSize= "20 "   OnRowEditing= "GridView1_RowEditing "   OnRowDeleting= "GridView1_RowDeleting "   OnRowUpdating= "GridView1_RowUpdating "   OnRowCancelingEdit= "GridView1_RowCancelingEdit ">
                <Columns>
                        <asp:BoundField   DataField= "登陆ID "   HeaderText= "登陆ID "   ReadOnly= "True "   />
                        <asp:BoundField   DataField= "姓名 "   HeaderText= "姓名 "   ReadOnly= "True "     />
                        <asp:BoundField   DataField= "电话 "   HeaderText= "电话 "   ReadOnly= "True "     />
                        <asp:BoundField   DataField= "手机 "   HeaderText= "手机 "   ReadOnly= "True "     />
                        <asp:BoundField   DataField= "课程名称 "   HeaderText= "课程名称 "     />
                        <asp:CheckBoxField   DataField= "付款 "   HeaderText= "付款 "     />
                        <asp:CommandField   HeaderText= "编辑 "   ShowEditButton= "True "   />
                        <asp:CommandField   HeaderText= "删除 "   ShowDeleteButton= "True "   />
                </Columns>
                  <RowStyle   BackColor= "#FFFBD6 "   ForeColor= "#333333 "   />
                                                <SelectedRowStyle   BackColor= "#FFCC66 "   Font-Bold= "True "   ForeColor= "Navy "   />
                                                <PagerStyle   BackColor= "#FFCC66 "   ForeColor= "#333333 "   HorizontalAlign= "Center "   />
                                                <HeaderStyle   BackColor= "#990000 "   Font-Bold= "True "   ForeColor= "White "   />
                                                <AlternatingRowStyle   BackColor= "White "   />


        </asp:GridView>
后台代码
    protected   void   GridView1_RowUpdating(object   sender,   GridViewUpdateEventArgs   e)
        {
                  OleDbConnection   oc   =   new   OleDbConnection( "Provider=Microsoft.Jet.OLEDB.4.0;Data   source= "   +   Server.MapPath(@ "~\App_Data\DataBase.aspx "));
                string   OleDbstr   =   "update   [用户信息]   set   课程名称= ' "
                        +   ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim()   +   " ',付款= ' "
                        +   ((CheckBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Checked.GetTypeCode()     +   " ' ";
                OleDbcom   =   new   OleDbCommand(OleDbstr,   oc);
                oc.Open();
                OleDbcom.ExecuteNonQuery();
                oc.Close();
                GridView1.EditIndex   =   -1;
                bind();
        }

[解决办法]
1.
付款 是什么数据类型?

2。
布尔 ?

string OleDbstr = "update [用户信息] set 课程名称= ' "
+ ((TextBox)(GridView1.Rows[e.RowIndex].Cells[4].Controls[0])).Text.ToString().Trim() + " ',付款= "
+ ((CheckBox)(GridView1.Rows[e.RowIndex].Cells[5].Controls[0])).Checked;


3。
Server.MapPath(@ "~\App_Data\DataBase.aspx "));
=========
这个 database.aspx 厉害,
事实上客户端无法访问的 App_Data 内部文件的, ASP.NET 已屏蔽,

若你要像 asp 时代哪样放下载,至少也要弄个 database.asax

[解决办法]
yesno类型--是否

其他的可以参照晓风的改,其次更新不过去,你可以单步调试下,看看你的sql语句在运行拼接sql语句后是否正确!

热点排行