我要实现一个功能,将gridview和textbox上的数据同时添加到数据库,如图
在线等

解决方案 »

  1.   

    循环生成model执行插入或修改方法。
    每一条订单存一次。
      

  2.   

    如果是每个单都保存一次收货人就遍历绑定的datatable,吧每条信息都写一次,如果是只保存一次,就在吧所有的订单号拼接起来,有一个特殊符号分开,在加上收货人信息存到另一个表
      

  3.   

      那就要循环gridview的数据添加了。
      

  4.   

    用个循环读出gridview中的在插进去
      

  5.   

    点击确定的时候将GridView中的数据循环读取出来.string names="";
    //將GridView中的數據循環拿出來
    for (int i = 0; i < grdLinkMan.Rows.Count; i++)
    {
     names=names+grdLinkMan.Rows[i].Cells[2].Text+",";
    }
    //收货人
    string consignee=this.txt收货人.text;
    //添加方法
      

  6.   

    当点击确定时,不如dgv
    dgv.rows.add("1","2","3");
      

  7.   

    在点击确定之后 ,循环得到gridview的数据之后  再把textbox的数据 提取 添加到你想要添加的表 
      

  8.   

    就是直接用一个变量接收循环得到的玩具名那列的值啊.在获取几个TextBox中的值,将这几个值用一个添加方法保存进去不就完了么.
      

  9.   

    循环遍历gridview数据,然后添加。
      

  10.   

    一个循环  循环列表
    string name=i行   玩具名列  的值保存方法(name,text地址,text姓名)
    { 
          sql=。
          。。
      

  11.   

    如果是点击确定按钮将数据添加到另一张表里,是在确定按钮里写那些代码吗
    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>");
        }
      

  12.   

    for循环读取控件每个属性,添加进数据库,至于textbox添加就简单么
      

  13.   

    string sName = gridview1.rows[i].cells[2].text; //这就是玩具名
      

  14.   

    何必这样的,你绑定的时候不是有个datatable么
    你去datatable里面循环遍历不就可以了么
      

  15.   


    //假设dt是你图中GridView绑定的那个table
    string sname = ""; //定义用了接收玩具名
    foreach (DataRow dr in dt.Rows)
    {
         sname = dr["玩具名的列的列名"].ToString();
         //接下来你要做什么操作就随便你了
    }
      

  16.   


    tring names="";
    //將GridView中的數據循環拿出來grdLinkMan是GridView的Id
    for (int i = 0; i < grdLinkMan.Rows.Count; i++)
    {
     names=names+grdLinkMan.Rows[i].Cells[2].Text+",";
    }你这样得不到玩具的名字吗?
      

  17.   

    前臺 <table style="width: 100%; table-layout: fixed;">
                                                                    <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>
      

  18.   


     //將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);
                            }
                        }
      

  19.   

    循环什么的代码要写在button按钮里吗