且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

将gridview的所有dropdownlist值存储到sql表中

更新时间:2023-01-06 18:11:47

foreach(GridViewRow gvr in GridView1.Rows)
    {
        if (gvr.RowType == DataControlRowType.DataRow)
        {
            string value = ((DropDownList)gvr.FindControl("didDdl")).SelectedValue;

           //here write code for inserting in sql table.use parameterized query for preventing from sql injection.

        }
    }





参见下面的参数化查询示例链接



http:// *** .com / questions / 12301776 / problems-insertion-to-sql-table [ ^ ]



谢谢



see example of parameterized query in below link

http://***.com/questions/12301776/problems-inserting-to-sql-table[^]

Thanks


protected void upload_Click(object sender, EventArgs e)
{

      for (int j = 0; j < GridView1.Rows.Count; j++)
        {

TextBox TextBox1 =(TextBox)GridView1.Row[j].FindControl("TextBox1 ");
DropDownList Eligible=(DropWownList)GridView1.Row[j].FindControl("Eligible");

            //con.Open();
                SqlCommand comm = new SqlCommand("insert into sender '" + TextBox1 .Text + "','" + Eligible.Item[Eligible.SelectedIndex].Value + "'", con);
                if (con.State.Equals(ConnectionState.Open))
                {
                    comm.ExecuteNonQuery();
                }
            }


}