如何在datagrid里修改数据,然后将checkbox的数据写入到数据库中呢??初学没有什么分,麻烦大家帮忙~~~~~~~~~~~~~~~~~~~~~~~~

ASP_sem 2007-12-18 03:15:28


如何在datagrid里修改数据,然后写入到数据库中呢??
如图,写入由checkbox选中的数据,包括上面的文本框内的数据都写入数据库要怎么写么??
...全文
222 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
╭═══╮ ╭═══╮ ╭══════╮   
╰╮ ╭╯ ╰╮ ╭╯ ╰╮ ╭══╮╰╮  
 ║ ║   ║ ║   ║ ║  ╰╮╰╮ 
 ║ ║   ║ ║   ║ ║   ║ ║ 
 ║ ║   ║ ║   ║ ║  ╭╯╭╯ 
 ║ ║   ║ ║   ║ ╰══╯╭╯  
 ║ ║   ║ ║   ║ ╭═══╯   
 ║ ║   ║ ║   ║ ║       
 ╰╮╰╮ ╭╯╭╯   ║ ║       
  ╰╮╰═╯╭╯   ╭╯ ╰╮      
   ╰═══╯    ╰═══╯
帮忙帮忙啊
zhao8155363 2007-12-19
  • 打赏
  • 举报
回复
╭═══╮ ╭═══╮ ╭══════╮   
╰╮ ╭╯ ╰╮ ╭╯ ╰╮ ╭══╮╰╮  
 ║ ║   ║ ║   ║ ║  ╰╮╰╮ 
 ║ ║   ║ ║   ║ ║   ║ ║ 
 ║ ║   ║ ║   ║ ║  ╭╯╭╯ 
 ║ ║   ║ ║   ║ ╰══╯╭╯  
 ║ ║   ║ ║   ║ ╭═══╯   
 ║ ║   ║ ║   ║ ║       
 ╰╮╰╮ ╭╯╭╯   ║ ║       
  ╰╮╰═╯╭╯   ╭╯ ╰╮      
   ╰═══╯    ╰═══╯
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
╭═══╮ ╭═══╮ ╭══════╮   
╰╮ ╭╯ ╰╮ ╭╯ ╰╮ ╭══╮╰╮  
 ║ ║   ║ ║   ║ ║  ╰╮╰╮ 
 ║ ║   ║ ║   ║ ║   ║ ║ 
 ║ ║   ║ ║   ║ ║  ╭╯╭╯ 
 ║ ║   ║ ║   ║ ╰══╯╭╯  
 ║ ║   ║ ║   ║ ╭═══╯   
 ║ ║   ║ ║   ║ ║       
 ╰╮╰╮ ╭╯╭╯   ║ ║       
  ╰╮╰═╯╭╯   ╭╯ ╰╮      
   ╰═══╯    ╰═══╯
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
感谢a11377815 不厌其烦的教我,谢谢谢谢
大正他爹 2007-12-19
  • 打赏
  • 举报
回复
遍历,。
a11377815 2007-12-19
  • 打赏
  • 举报
回复
汗,看着就心寒,,,我是群里的那个哈哈,看着你慢慢这里问,,,郁闷,,
yjwang0621 2007-12-19
  • 打赏
  • 举报
回复
不就是遍历dg中的checkbox吗?
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
再把.CS代码发下,说明下我datagrid里的数据不是从数据库中绑定的,是从其他地方通过字符串的方式传递过来的


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;


namespace PartEbuy
{
/// <summary>
/// checkchild 的摘要说明。
/// </summary>
public class checkchild : System.Web.UI.Page

{
protected PartEbuy.DBase DB_DO=new DBase();
protected System.Web.UI.WebControls.Button DelBtn;
protected System.Web.UI.WebControls.Button Button2;
PartEbuy.PURMF_WEB PW=new PURMF_WEB();
protected System.Web.UI.WebControls.Button SABtn;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox Purmf_dpno;
protected System.Web.UI.WebControls.TextBox PURMF_APPLYUNIT;
protected System.Web.UI.WebControls.TextBox PURMF_APPLYDATE;
protected System.Web.UI.WebControls.TextBox PURMF_USING;
ArrayList al = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)

{
//this.Qpurtrans();
string flowsnID = string.Empty;
string flowsnID1 = string.Empty;
string flowsnID2 = string.Empty;
string flowsnID3 = string.Empty;
if (Request.QueryString["Qpur_flowsn"] != null)
{

flowsnID = Request.QueryString["Qpur_dpno"];
flowsnID1 = Request.QueryString["Qpur_flowsn"];
flowsnID2 = Request.QueryString["Qpur_applyunitname"];
flowsnID3 = Request.QueryString["Qpur_usedate"];
}

Purmf_dpno.Text = flowsnID.ToString();
PURMF_USING.Text = "对应"+flowsnID1.ToString()+"之请购单子件选购" ;
PURMF_APPLYUNIT.Text = flowsnID2.ToString();
this.PURMF_APPLYDATE.Text=DateTime.Now.ToShortDateString();
string purmfdpno="";
purmfdpno=this.Purmf_dpno.Text.ToString().Trim().Trim();
if (purmfdpno!="")
{

string chkchild=PW.checkchild(purmfdpno);
string flagvalue=chkchild.Substring(0,1).Trim();
if (flagvalue=="1" ¦ flagvalue=="0")
{
if (flagvalue =="1")

{

//将数组转化为datatable
string [] infoarray = chkchild.Split(';');
//构建新的 table,并为其添加列
DataTable dt = new DataTable();
dt.Columns.Add("厂商", typeof(string));
dt.Columns.Add("车型",typeof(string));
dt.Columns.Add("子件件号", typeof(string));
dt.Columns.Add("子件件名", typeof(string));
dt.Columns.Add("数量", typeof(string));
dt.Columns.Add("计量单位", typeof(string));
dt.Columns.Add("需用日期", typeof(string));

//循环数据源,为dt赋值
for (int i= 0; i < infoarray.Length; i++)
{
string detail1=infoarray[i]+","+flowsnID3;
string [] detail = detail1.Split(',');
//string[] detail = detail1.Split(new char[] { ','});
DataRow row = dt.NewRow();//获取带有dt结构的空数据行
for (int n = 0; n < 7; n++)//为空数据行添加数据
{
row[n] = detail[n+1];

}
dt.Rows.Add(row);//将带有数据的行添加到dt中


}
this.DataGrid1.DataSource = dt;
this.DataGrid1.DataBind();
}
if (flagvalue =="0")
{
Response.Write ("错误");
}
}
}
}
}


#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SABtn.Click += new System.EventHandler(this.SABtn_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
private void SABtn_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox chkExport;
//如果要全选
if(SABtn.Text == "全选")
{
//循环设置DataGrid控件中的项
foreach(DataGridItem oDataGridItem in DataGrid1.Items)
{
//建立模板列中CheckBox控件的引用
chkExport = (CheckBox)oDataGridItem.FindControl("Checkbox1");
//选中
chkExport.Checked =true;
}

SABtn.Text = "全消";
}
else
{
foreach(DataGridItem oDataGridItem in DataGrid1.Items)
{
//建立模板列中CheckBox控件的引用
chkExport = (CheckBox)oDataGridItem.FindControl("Checkbox1");
//取消
chkExport.Checked = false;
}
SABtn.Text = "全选";
}
}

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{


}

private void Button2_Click(object sender, System.EventArgs e)
{

}


}
}
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
接上面的
<td><asp:datagrid id="DataGrid1" runat="server" Width="750px" ForeColor="Black" GridLines="Vertical"
BackColor="White" BorderStyle="Solid" Height="11px" AllowPaging="True" AutoGenerateColumns="False"
AllowCustomPaging="True" BorderColor="#999999" CellPadding="3" BorderWidth="1px" AllowSorting="True"
PagerStyle-Mode="NumericPages" PagerStyle-HorizontalAlign="Right" Font-Names="宋体">
<FooterStyle Font-Size="XX-Small" HorizontalAlign="Center" Height="10px" VerticalAlign="Bottom"
BackColor="#CCCCCC"></FooterStyle>
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#000099"></SelectedItemStyle>
<AlternatingItemStyle Font-Size="X-Small" BackColor="#CCCCCC"></AlternatingItemStyle>
<HeaderStyle Font-Size="X-Small" Font-Bold="True" HorizontalAlign="Center" Height="10px" ForeColor="White"
VerticalAlign="Middle" BackColor="Black"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="勾选">
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BackColor="#337FB2"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:checkbox id="Checkbox1" runat="server"></asp:checkbox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="序号">
<HeaderStyle HorizontalAlign="Center" ForeColor="White" BackColor="#337FB2"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<%#(((System.Web.UI.WebControls.DataGridItem)Container).ItemIndex+1)+(DataGrid1.PageSize)*(DataGrid1.CurrentPageIndex)%>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:TemplateColumn>
<asp:BoundColumn DataField="厂商" ReadOnly="True" HeaderText="厂商">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="车型" ReadOnly="True" HeaderText="车型">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="子件件号" HeaderText="子件件号">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:BoundColumn>
<asp:BoundColumn DataField="子件件名" HeaderText="子件件名">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="数量">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:TextBox id=PURMF_NUMBER runat="server" tabIndex="3" Width="64px" CssClass="inputcss" Text='<%# DataBinder.Eval(Container, "DataItem.数量") %> '>
</asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:TemplateColumn>
<asp:TemplateColumn HeaderText="序列交货">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:dropdownlist id="PURMF_XL" runat="server">
<asp:ListItem Value="是">是</asp:ListItem>
<asp:ListItem Value="否">否</asp:ListItem>
</asp:dropdownlist>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:TemplateColumn>
<asp:BoundColumn DataField="计量单位" HeaderText="计量单位">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:BoundColumn>
<asp:TemplateColumn HeaderText="需用日期">
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<ItemStyle HorizontalAlign="Center"></ItemStyle>
<ItemTemplate>
<asp:TextBox id="PURMF_USEDATE" runat="server" tabIndex="3" Width="64px" CssClass="inputcss" Text='<%# DataBinder.Eval(Container, "DataItem.需用日期") %>'>
</asp:TextBox>
</ItemTemplate>
<FooterStyle HorizontalAlign="Center"></FooterStyle>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Center" ForeColor="Black" BackColor="#999999" Mode="NumericPages"></PagerStyle>
</asp:datagrid><asp:button id="SABtn" runat="server" CssClass="ButtonCSS" Text="全选"></asp:button>     
<asp:button id="SaveBtn" runat="server" CssClass="ButtonCSS" Text="保存"></asp:button></td>
</tr>
</TBODY>
</table>
</td>
</tr>
</TBODY>
</table>
</form>
</body>
</HTML>
ASP_sem 2007-12-19
  • 打赏
  • 举报
回复
希望大家能在我的代码的基础上改哦,例子网上太多了,我刚学,很多都看不懂,但是老板又一直催我,没有办法,谢谢大家热心的帮助,谢谢~~
下面是我的 .ASPX的代码,加上之前发的.CS 代码,麻烦大家了~~
<%@ Page language="c#" Codebehind="checkchild.aspx.cs" AutoEventWireup="false" Inherits="PartEbuy.checkchild" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>子件请购</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="C#" name="CODE_LANGUAGE">
<LINK href="Include/BasicLayout.css" type="text/css" rel="stylesheet">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<table id="Table0" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 709px; POSITION: absolute; TOP: 40px; HEIGHT: 300px"
borderColor="#000000" cellSpacing="0" borderColorDark="#ffffff" cellPadding="0" borderColorLight="#000000"
border="1">
<TBODY>
<tr>
<td style="HEIGHT: 23px" align="center">  <FONT face="宋体" size="2">子件选购</FONT>
</td>
</tr>
<tr>
<td style="HEIGHT: 161px" align="center">
<TABLE id="Table1" style="WIDTH: 700px; HEIGHT: 80px" cellSpacing="0" cellPadding="0" width="700"
border="0">
<TBODY>
<TR>
<TD style="WIDTH: 75px; HEIGHT: 20px" align="right"><FONT face="宋体">母件:</FONT></TD>
<TD style="WIDTH: 250px; HEIGHT: 20px"><asp:textbox id="Purmf_dpno" tabIndex="1" runat="server" ReadOnly="True" AutoPostBack="True"
Width="146px" CssClass="inputcss" MaxLength="13"></asp:textbox><FONT face="宋体" color="red"></FONT></TD>
<TD style="WIDTH: 75px; HEIGHT: 20px" align="right"><FONT face="宋体">用途说明:</FONT></TD>
<TD style="WIDTH: 250px; HEIGHT: 20px"><asp:textbox id="PURMF_USING" tabIndex="1" runat="server" ReadOnly="True" Width="200px" CssClass="inputcss"></asp:textbox></TD>
</TR>
<TR>
<TD style="WIDTH: 75px; HEIGHT: 20px" align="right"><FONT face="宋体">请购单位:</FONT></TD>
<TD style="WIDTH: 250px; HEIGHT: 20px"><asp:textbox id="PURMF_APPLYUNIT" tabIndex="1" runat="server" ReadOnly="True" AutoPostBack="True"
Width="146px" CssClass="inputcss" MaxLength="13"></asp:textbox><FONT face="宋体" color="red"></FONT></TD>
<TD style="WIDTH: 75px; HEIGHT: 20px" align="right"><FONT face="宋体">请购日期:</FONT></TD>
<TD style="WIDTH: 250px; HEIGHT: 20px"><asp:textbox id="PURMF_APPLYDATE" tabIndex="1" runat="server" ReadOnly="True" AutoPostBack="True"
Width="146px" CssClass="inputcss" MaxLength="13"></asp:textbox><FONT face="宋体" color="red"></FONT></TD>
</TR>
<TR>
<TD style="WIDTH: 87px; HEIGHT: 26px" align="right"> <IMG height="15" src="images/ico_user.gif" width="14"> 操作用户:</TD>
<TD style="HEIGHT: 26px" colSpan="7"><asp:textbox id="douser" runat="server" Width="160px" CssClass="inputcss" ReadOnly="True" Height="24px"></asp:textbox></TD>
</TR>
</TBODY>
</TABLE>
</td>
</tr>
<tr>
<td>
<table style="WIDTH: 90%; HEIGHT: 90%" align="center" border="0">
<TBODY>
<tr>


满衣兄 2007-12-19
  • 打赏
  • 举报
回复
//Web.config

<appSettings>
<add key="ConnectionString" value="server=127.0.0.1;database=test;uid=sa;pwd=***"></add>
</appSettings>

//WebForm1.aspx

<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="WebTest.WebForm1" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:Button id="Button1" style="Z-INDEX: 102; LEFT: 184px; POSITION: absolute; TOP: 80px" runat="server"
Width="72px" Text="提交"></asp:Button>
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 184px; POSITION: absolute; TOP: 120px" runat="server">
<Columns>
<asp:TemplateColumn>
<ItemTemplate>
<asp:CheckBox id="CheckBox1" runat="server"></asp:CheckBox>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox id="TextBox1" runat="server"></asp:TextBox>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>

//WebForm1.cs

using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;

namespace WebTest
{
/// <summary>
/// WebForm1 的摘要说明。
/// </summary>
public class WebForm1 : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.Button Button1;

private void Page_Load(object sender, System.EventArgs e)
{
if(!IsPostBack)
{
InitData();//初始化数据
}
}
#region method
private void InitData()
{
this.DataGrid1.DataSource = GetDataSet();
this.DataGrid1.DataBind();
}
private DataSet GetDataSet()
{
// 建立数据源,从web.config中读取连接字符串
SqlConnection con = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"));
SqlDataAdapter da = new SqlDataAdapter("select * from usertable",con);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
#endregion

#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.Button1.Click += new System.EventHandler(this.Button1_Click);
this.DataGrid1.ItemDataBound += new System.Web.UI.WebControls.DataGridItemEventHandler(this.DataGrid1_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

#region event
private void Button1_Click(object sender, System.EventArgs e)
{
string sql = string.Empty;
for(int i = 0;i<DataGrid1.Items.Count;i++)
{
CheckBox newCheckBox = DataGrid1.Items[i].FindControl("CheckBox1") as CheckBox;
if(newCheckBox.Checked)
{
sql+="update usertable set isforbid=1 where username = '"+DataGrid1.Items[i].Cells[1].Text+"';";
}
else
{
sql+="update usertable set isforbid=0 where username = '"+DataGrid1.Items[i].Cells[1].Text+"';";
}
}
if(sql!=string.Empty)
{
SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings.Get("ConnectionString"));
SqlCommand cmd= new SqlCommand(sql, conn);
cmd.CommandTimeout = 0;//设置一条语句的执行时间为无限
try
{
if ((conn != null)&&(conn.State != ConnectionState.Open))
{
conn.Open();
}
cmd.ExecuteNonQuery();
}
catch(Exception ex)
{
Response.Write(ex.Message);
}
finally
{
if ((conn != null) && (conn.State != ConnectionState.Closed))
{
conn.Close();
}
}
InitData();//重新绑定数据
}
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemIndex>-1)
{
if(e.Item.Cells[3].Text.ToLower().Trim()=="false")
{
(e.Item.Cells[0].FindControl("CheckBox1") as CheckBox).Checked=false;
}
else
{
(e.Item.Cells[0].FindControl("CheckBox1") as CheckBox).Checked=true;
}
}
}
#endregion

}
}


//生成数据库,表

if exists (select * from sysobjects where id = OBJECT_ID('[usertable]') and OBJECTPROPERTY(id, 'IsUserTable') = 1)
DROP TABLE [usertable]

CREATE TABLE [usertable] (
[username] [nvarchar] (50) NOT NULL,
[userpwd] [nvarchar] (50) NOT NULL,
[isforbid] [bit] NOT NULL DEFAULT (1))

INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( 'yfq','yfq',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '1','1',1)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '2','2',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '3','3',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '4','4',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '5','5',1)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '6','6',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '7','7',0)
INSERT [usertable] ([username],[userpwd],[isforbid]) VALUES ( '8','8',0)

//这个小例子,希望可以帮助你
ASP_sem 2007-12-18
  • 打赏
  • 举报
回复
up 。。。。
lovehongyun 2007-12-18
  • 打赏
  • 举报
回复
up
ASP_sem 2007-12-18
  • 打赏
  • 举报
回复
我把代码贴出来,能够指导我的人就指导教育我,谢谢哦~~
ASP_sem 2007-12-18
  • 打赏
  • 举报
回复
.CS文件
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;



namespace PartEbuy
{
/// <summary>
/// checkchild 的摘要说明。
/// </summary>
public class checkchild : System.Web.UI.Page

{
protected PartEbuy.DBase DB_DO=new DBase();
protected System.Web.UI.WebControls.Button DelBtn;
protected System.Web.UI.WebControls.Button Button2;
PartEbuy.PURMF_WEB PW=new PURMF_WEB();
protected System.Web.UI.WebControls.Button SABtn;
protected System.Web.UI.WebControls.Button btnSubmit;
protected System.Web.UI.WebControls.DataList DataList1;
protected System.Web.UI.WebControls.DataGrid DataGrid1;
protected System.Web.UI.WebControls.TextBox Purmf_dpno;
protected System.Web.UI.WebControls.TextBox PURMF_APPLYUNIT;
protected System.Web.UI.WebControls.TextBox PURMF_APPLYDATE;
protected System.Web.UI.WebControls.TextBox PURMF_USING;
ArrayList al = new ArrayList();
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!IsPostBack)

{
//this.Qpurtrans();
string flowsnID = string.Empty;
string flowsnID1 = string.Empty;
string flowsnID2 = string.Empty;
string flowsnID3 = string.Empty;
if (Request.QueryString["Qpur_flowsn"] != null)
{

flowsnID = Request.QueryString["Qpur_dpno"];
flowsnID1 = Request.QueryString["Qpur_flowsn"];
flowsnID2 = Request.QueryString["Qpur_applyunitname"];
flowsnID3 = Request.QueryString["Qpur_usedate"];
}

Purmf_dpno.Text = flowsnID.ToString();
PURMF_USING.Text = "对应"+flowsnID1.ToString()+"之请购单子件选购" ;
PURMF_APPLYUNIT.Text = flowsnID2.ToString();
this.PURMF_APPLYDATE.Text=DateTime.Now.ToShortDateString();
string purmfdpno="";
purmfdpno=this.Purmf_dpno.Text.ToString().Trim().Trim();
if (purmfdpno!="")
{

string chkchild=PW.checkchild(purmfdpno);
string flagvalue=chkchild.Substring(0,1).Trim();
if (flagvalue=="1" | flagvalue=="0")
{
if (flagvalue =="1")

{

//将数组转化为datatable
string [] infoarray = chkchild.Split(';');
//构建新的 table,并为其添加列
DataTable dt = new DataTable();
dt.Columns.Add("厂商", typeof(string));
dt.Columns.Add("车型",typeof(string));
dt.Columns.Add("子件件号", typeof(string));
dt.Columns.Add("子件件名", typeof(string));
dt.Columns.Add("数量", typeof(string));
dt.Columns.Add("计量单位", typeof(string));
dt.Columns.Add("需用日期", typeof(string));

//循环数据源,为dt赋值
for (int i= 0; i < infoarray.Length; i++)
{
string detail1=infoarray[i]+","+flowsnID3;
string [] detail = detail1.Split(',');
//string[] detail = detail1.Split(new char[] { ','});
DataRow row = dt.NewRow();//获取带有dt结构的空数据行
for (int n = 0; n < 7; n++)//为空数据行添加数据
{
row[n] = detail[n+1];

}
dt.Rows.Add(row);//将带有数据的行添加到dt中


}
this.DataGrid1.DataSource = dt;
this.DataGrid1.DataBind();
}
if (flagvalue =="0")
{
Response.Write ("错误");
}
}
}
}
}


#region Web 窗体设计器生成的代码
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.SABtn.Click += new System.EventHandler(this.SABtn_Click);
this.Button2.Click += new System.EventHandler(this.Button2_Click);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion
private void SABtn_Click(object sender, System.EventArgs e)
{
System.Web.UI.WebControls.CheckBox chkExport;
//如果要全选
if(SABtn.Text == "全选")
{
//循环设置DataGrid控件中的项
foreach(DataGridItem oDataGridItem in DataGrid1.Items)
{
//建立模板列中CheckBox控件的引用
chkExport = (CheckBox)oDataGridItem.FindControl("Checkbox1");
//选中
chkExport.Checked =true;
}

SABtn.Text = "全消";
}
else
{
foreach(DataGridItem oDataGridItem in DataGrid1.Items)
{
//建立模板列中CheckBox控件的引用
chkExport = (CheckBox)oDataGridItem.FindControl("Checkbox1");
//取消
chkExport.Checked = false;
}
SABtn.Text = "全选";
}
}

private void DataGrid1_SelectedIndexChanged(object sender, System.EventArgs e)
{


}

private void Button2_Click(object sender, System.EventArgs e)
{

}


}
}
ASP_sem 2007-12-18
  • 打赏
  • 举报
回复
因为是初学很多看不懂的,麻烦大家能注释一下 哦,谢谢哦
满衣兄 2007-12-18
  • 打赏
  • 举报
回复

private void btnDelete_Click(object sender, System.EventArgs e)
{
Artdio.BLL.define_region op = new Artdio.BLL.define_region();
string region_group_id = Request.QueryString["region_group_id"].ToString();
for(int i = 0;i<DataGrid1.Items.Count;i++)
{
CheckBox newCheckBox = DataGrid1.Items[i].FindControl("CheckBox1") as CheckBox;
if(newCheckBox.Checked)
{
op.Delete(Convert.ToInt32(region_group_id),((Label)DataGrid1.Items[i].Cells[2].FindControl("Label1")).Text);
}
}
Get_Rows_Count();
Get_DataReader();
Artdio.Web.Class.Currency writelog = new Artdio.Web.Class.Currency();
writelog.WriteLog(this,Operation_Type.delete,"define_region","delete region");
}


//这样是遍历DataGrid1上的CheckBox ,然后你只要构造sql语句就行了
PCI_E 2007-12-18
  • 打赏
  • 举报
回复
不知道你的DataGrid上的checkBox是dataGrid自己特性还是你自己做进去的,
如果是自己做进去去的,那样笨点的办法就是循环这个datagrid,判断哪些checkBox是选中的,然后提取对应数据,可以拼成一个XML,一次性提交回数据库,用存储过程分解XML,然后修改数据

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧