我要实现一个功能,将gridview和textbox上的数据同时添加到数据库,如图
在线等
在线等
解决方案 »
- 关于memcache公用服务端问题
- 如何让页面过期时重定向到登录页面(注意:用户自定义设置)
- 怎么取得两字符串的差值:"9999999999999999999"-"9999999999999999899"?
- 关于Web控件不响应事件的问题,急,在线等!
- 怪哉!怪哉!为什么我的GridView.Rows[1].Cell[1].Text读不出任何值来??
- 提一个有关获取HTML控件值的问题。挺复杂的,希望大家能进来看看
- asp.net 如何程序实现表单提交过程?
- 利用dropdownlist控件,的困惑!
- .net问题
- 请教 大佬重写 FindByNameAsync
- 字符串 方法
- 获取不到session的问题
每一条订单存一次。
//將GridView中的數據循環拿出來
for (int i = 0; i < grdLinkMan.Rows.Count; i++)
{
names=names+grdLinkMan.Rows[i].Cells[2].Text+",";
}
//收货人
string consignee=this.txt收货人.text;
//添加方法
dgv.rows.add("1","2","3");
string name=i行 玩具名列 的值保存方法(name,text地址,text姓名)
{
sql=。
。。
}
protected void btnOsubmit_Click(object sender, EventArgs e)
{
//建立Connection对象
string connectionString = @"Data Source=.\sqlexpress;Initial Catalog=toyDB;User ID=sa;passWord=1234";
SqlConnection con = new SqlConnection(connectionString);
//建立Command对象
string sql5= "select toy_name from toy_order";
string sql = "insert into toy_orderlist(coustom_name,coustom_tel,coustom_add) values('" + txtCoustomName .Text+ "','"+txtCoustomTel.Text+"','"+txtCoustomeAdd+"')";
SqlCommand cmd = new SqlCommand(sql5,sql, con);
//执行插入操作
con.Open(); //打开数据库
cmd.ExecuteNonQuery();
con.Close(); //关闭数据库
Response.Write("<script language='javascript'>alert('添加订单成功!');window.location.href('toyOrderlistUser.aspx');</script>");
}
你去datatable里面循环遍历不就可以了么
//假设dt是你图中GridView绑定的那个table
string sname = ""; //定义用了接收玩具名
foreach (DataRow dr in dt.Rows)
{
sname = dr["玩具名的列的列名"].ToString();
//接下来你要做什么操作就随便你了
}
tring names="";
//將GridView中的數據循環拿出來grdLinkMan是GridView的Id
for (int i = 0; i < grdLinkMan.Rows.Count; i++)
{
names=names+grdLinkMan.Rows[i].Cells[2].Text+",";
}你这样得不到玩具的名字吗?
<tr>
<td>
<asp:Button ID="txtAddRow" runat="server" Text="添加" OnClick="txtAddRow_Click" meta:resourcekey="txtAddRowResource1">
</asp:Button>
</td>
</tr>
<tr>
<td>
<asp:GridView ID="grdLinkMan" CssClass="grdlinkMandd" Width="100%" runat="server"
AutoGenerateColumns="False" ShowFooter="True" OnSelectedIndexChanged="grdLinkMan_SelectedIndexChanged"
meta:resourcekey="grdLinkManResource1">
<Columns>
<asp:CommandField HeaderText="刪除" FooterText="輸入" SelectText="刪除" ShowSelectButton="True"
meta:resourcekey="CommandFieldResource1">
<HeaderStyle HorizontalAlign="Left" Width="45px" Wrap="False" />
<ItemStyle Wrap="False" Width="45px" />
</asp:CommandField>
<asp:TemplateField HeaderText="聯絡人" meta:resourcekey="TemplateFieldResource1">
<ItemTemplate>
<asp:Label ID="lbLiaisons" runat="server" Text='<%# Bind("Liaisons") %>' meta:resourcekey="lbLiaisonsResource1"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtLiaisons" Width="81%" runat="server" meta:resourcekey="txtLiaisonsResource2"></asp:TextBox>
</FooterTemplate>
<HeaderStyle HorizontalAlign="Left" />
</asp:TemplateField>
<asp:TemplateField HeaderText="職位" meta:resourcekey="TemplateFieldResource10">
<HeaderStyle HorizontalAlign="Left" />
<ItemTemplate>
<asp:Label ID="lbPosition" runat="server" Text='<%# Bind("Position") %>' meta:resourcekey="lbPositionResource1"></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:TextBox ID="txtPosition" Width="81%" runat="server" meta:resourcekey="txtPositionResource1"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
//將GridView中的數據循環拿出來
for (int i = 0; i < grdLinkMan.Rows.Count; i++)
{
Label lbLiaisons = grdLinkMan.Rows[i].FindControl("lbLiaisons") as Label;
Label lbPosition = grdLinkMan.Rows[i].FindControl("lbPosition") as Label;
//如果不是默認數據則加入數據庫
if (lbLiaisons.Text != "")
{
LinkMan linkman = new LinkMan();
linkman.Liaisons = lbLiaisons.Text;
linkman.Position = lbPosition.Text;
linkman = DBDataType.NullToDefault(linkman) as LinkMan;
UnitOfWork.Add(linkman);
}
}