从GridView持久化数据

从GridView持久化数据

本文介绍了从GridView持久化数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果其中包含一些控件,如DropDownLists,TextBoxes,RadioButtons,如何从GridView上载数据并将其存储在数据库中?

这是代码
当按钮A单击以将数据从GridView上载到数据库时

How do you upload the data From GridView and store in database if we have some controls like DropDownLists,TextBoxes,RadioButtons included in it?

Here Is Code
When A of Button Click to upload the data to Database from GridView

protected void Button2_Click(object sender, EventArgs e)
    {
        int i;
        for (i = 0; i < gridview2.Rows.Count; i++)
        {
            SqlCommand cmd = new SqlCommand("insert into rep values('"+gridview2.Rows[i].Cells[0].Text+"','" + gridview2.Rows[i].Cells[1].Text +"','" + gridview2.Rows[i].Cells[2].Text+ "','"+ gridview2.Rows[i].Cells[3].Text+ "')", con);

            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

        }




这里+ gridview2.Rows [i] .Cells [2] .Text +是一个下拉列表



+ gridview2.Rows [i] .Cells [3] .Text +是一个TextBoxes


请发布答案.




Here + gridview2.Rows[i].Cells[2].Text+ is a dropdownlist

and

+gridview2.Rows[i].Cells[3].Text+ is a TextBoxes


Please post the answers.

推荐答案




这篇关于从GridView持久化数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:18