WebForm获取选中行数值的问题
WebForm获取选中行数值的问题开发环境:
VS2010,WebForm,.NET 4.0
控件:
GridView+Button
需求:
GridView 展示多行数据, 用户选择其中一行,点击Button,将选中行的其中2列数据写入新表;
问题:
写入新表后, 发现选中数据始终为空值;
主要代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebIMS.MeetingRoom
{
public partial class Frm_Meeting_Order : System.Web.UI.Page
{
public string select_room_name = "";
public string select_room_adds = "";
..............
..................
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int itmpid = int.Parse(Session["tmpID"].ToString());
select_room_name = GridView1.Rows[itmpid].Cells[1].Text;//读取Gridview里所选行的第1列
select_room_adds = GridView1.Rows[itmpid].Cells[3].Text;//读取Gridview里所选行的第3列
Notice0.Text = select_room_name;//选中时select_room_name是有值的;
Session.Remove("tmpID"); //清除Session
}
..................
.................
string strCmd = string.Format("insert into ");
strCmd += ("Meeting_Order(Room_Name,Order_Date,Time_Start,Time_End,Subject,Remark,Number_People,Time_Created,Name_Created,Name_ID_Created,Tel_Created,Email_Created) ");
strCmd += ("values('" + select_room_name + "','" + Order_Date + "'");//但这时select_room_name的值不知道为什么变成空值了??;
strCmd += (",'" + startTime + "','" + endTime + "','" + Subject.Text.Trim() + "','" + Remark.Text.Trim() + "' ");
strCmd += (",'" + Number_People.Text.Trim() + "','" + DateTime.Now.ToString() + "','" + Session["Str_Name"] + "','" + Session["Str_ID"] + "'");
strCmd += (",'" + Session["Str_Tel"] + "','" + Session["Str_Email"] + "' "); //创建人电话,Email
strCmd += (")"); //SQL 语句结束
try
{
SqlConnection sqlConn_insert = new SqlConnection(DBHelper.constr); //准备写入记录
sqlConn_insert.Open();
SqlCommand sqlCmd = new SqlCommand(strCmd, sqlConn_insert);
if (sqlCmd.ExecuteNonQuery() > 0) //写入记录
{
//新增成功!
Notice.Text = "会议室预约成功!会议室是:" + select_room_name;
sqlConn_insert.Close();
..................
.................