| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 413 人关注过本帖
标题:WebForm获取选中行数值的问题
只看楼主 加入收藏
smilelake
Rank: 2
等 级:论坛游民
威 望:1
帖 子:31
专家分:30
注 册:2012-8-23
结帖率:0
收藏
 问题点数:0 回复次数:0 
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();
..................
.................
搜索更多相关主题的帖子: 中行 用户 开发 public 
2013-01-14 23:43
快速回复:WebForm获取选中行数值的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016965 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved