grivdview 模板之dropdownlist完美结合

using System;
using System.Configuration;
using System.Data;

using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    string strconn = "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            gridBind();
        }
    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
  
    public DataSet BackDs()
    {
        SqlConnection con;
        string strconn = "server=.;database=SIDB;uid=sa;pwd=01120817lhh";
        string strSql = "SELECT ID,NameCN FROM Manu where id<2 ";
        con = new SqlConnection(strconn);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(strSql, con);
        da.Fill(ds);
        return ds;
    }

    public DataSet BackDlDs()
    {
        SqlConnection con;
        string strconn = "server=.;database=SIDB;uid=sa;pwd=----";
        string strSql = "SELECT ID,NameCN FROM Manu ";
        con = new SqlConnection(strconn);
        DataSet ds = new DataSet();
        SqlDataAdapter da = new SqlDataAdapter(strSql, con);
        da.Fill(ds);
        return ds;
       
    }

    public void gridBind()
    {
        DataSet FirDs = BackDs();
        GridView1.DataSource = FirDs.Tables[0];
        GridView1.DataBind();
       
    }

    protected void PageDropDownList_DataBound(object sender, EventArgs e)
    {

    }
    protected void PageDropDownList_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
    {
        DataSet Myds = BackDlDs();
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList goodsType = (DropDownList)e.Row.FindControl("DropDownList1");
            if (goodsType != null)
            {
                goodsType.DataSource = Myds.Tables[0].DefaultView;
                goodsType.DataTextField = "NameCN";
                goodsType.DataValueField = "ID";
                goodsType.DataBind();
            }
        }
    }

    protected void BtnAdd_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            int droplisttext = int.Parse(((DropDownList)row.FindControl("DropDownList1")).SelectedItem.Value);
            string textValues1=((TextBox)row.FindControl("TextBox1")).Text;
            string textValues2 = ((TextBox)row.FindControl("TextBox2")).Text;
            string textValues3 = ((TextBox)row.FindControl("TextBox3")).Text;
            string textValues4 = ((TextBox)row.FindControl("TextBox4")).Text;
            string textValues5 = ((TextBox)row.FindControl("TextBox5")).Text;
            string textValues6 = ((TextBox)row.FindControl("TextBox6")).Text;
            string strsql = "insert into Project (ManuID,Project,Client,StartTime,FinishTime,Quantity,Cost) values (@ManId,@Proj,@Client,@StaTime,@FiniTime,@qunT,@Cos)";
            SqlConnection sqconn = new SqlConnection(strconn);
            sqconn.Open();
            SqlCommand sqlcomm = new SqlCommand(strsql,sqconn);
            sqlcomm.Parameters.Add("@ManId",SqlDbType.Int);
            sqlcomm.Parameters["@ManId"].Value = droplisttext;
            sqlcomm.Parameters.Add("@Proj", SqlDbType.NVarChar, 50);
            sqlcomm.Parameters["@Proj"].Value = textValues1;
            sqlcomm.Parameters.Add("@Client", SqlDbType.NVarChar,200);
            sqlcomm.Parameters["@Client"].Value = textValues2;
            sqlcomm.Parameters.Add("@StaTime", SqlDbType.DateTime);
            sqlcomm.Parameters["@StaTime"].Value = textValues3;
            sqlcomm.Parameters.Add("@FiniTime", SqlDbType.DateTime);
            sqlcomm.Parameters["@FiniTime"].Value = textValues4;
            sqlcomm.Parameters.Add("@qunT", SqlDbType.NVarChar, 50);
            sqlcomm.Parameters["@qunT"].Value = textValues5;
            sqlcomm.Parameters.Add("@Cos", SqlDbType.NVarChar, 50);
            sqlcomm.Parameters["@Cos"].Value = textValues6;

            sqlcomm.ExecuteNonQuery();
            sqconn.Close();
          

        }
       
       
      
      
    }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值