关于gridview编辑下dropdownlist取值的问题?

以下是我的原代码:.CS代码usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usingSyste... 以下是我的原代码:
.CS代码

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Web.Security;
using System.Collections;
using System.Configuration;
using System.Drawing;
using System.IO.MemoryMappedFiles;
using System.IO;
using System.Text;

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bind();

}
}
public void bind()
{
string sqlStr = "select * from GoodsName";
SqlConnection cone = new SqlConnection("Data Source=JXL\\SQLEXPRESS;Initial Catalog=Jxl_Data;Integrated Security=True");
SqlDataAdapter sdp = new SqlDataAdapter(sqlStr,cone);
DataSet das = new DataSet();
sdp.Fill(das,"GoodsName");
GridView1.DataSource = das;
GridView1.DataKeyNames = new string[] { "Number" };
GridView1.DataBind();
}

protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{

if (((DropDownList)e.Row.FindControl("DropDownList1")) != null)
{
DropDownList ddlAddress = (DropDownList)e.Row.FindControl("DropDownList1");
SqlConnection sqlconn = new SqlConnection();
sqlconn.ConnectionString = "Data Source=JXL\\SQLEXPRESS;Initial Catalog=Jxl_Data;Integrated Security=True";
sqlconn.Open();
SqlDataAdapter sqldar = new SqlDataAdapter("select GoodsPlace from GoodsPlace", sqlconn);
sqldar.SelectCommand.CommandType = CommandType.Text;
DataSet Ds = new DataSet();
sqldar.Fill(Ds, "GoodsPlace");
ddlAddress.DataSource = Ds.Tables[0].DefaultView;
ddlAddress.DataTextField = "GoodsPlace";
ddlAddress.DataValueField = "GoodsPlace";
ddlAddress.DataBind();
//sqlconn.Close();
if ((HiddenField)e.Row.FindControl("HiddenField1") != null)
{
HiddenField hd = (HiddenField)e.Row.FindControl("HiddenField1");
ddlAddress.SelectedValue = hd.Value;
}
//ddlAddress.SelectedValue = ((HiddenField)e.Row.FindControl("HiddenField1")).Value;
}
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
bind();
}
protected void GridView1_RowEditing1(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
bind();
}
}
展开
 我来答
hmloo20101112
2011-11-07 · TA获得超过383个赞
知道小有建树答主
回答量:260
采纳率:0%
帮助的人:244万
展开全部
你试试((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式