我想将2下拉列表绑定到网格视图中 [英] i want to bind 2 dropdownlist into grid view
本文介绍了我想将2下拉列表绑定到网格视图中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想将两个DropDownList绑定到ASP.NET中的GridView中。
我用Databound事件绑定了一个DropDownList,但问题是我怎么能绑定GridView中的第二个DropDownList?
我的要求是1 dropdownlist选择autometically第二个dropdownlist绑定我绑下面的代码它不工作PLZ帮我任何一个... 。
public DataSet GetHeadName()
{
_conn = new SqlConnection(str);
_cmd = new SqlCommand( getheadname ,_ conn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.CommandText = getheadname;
SqlDataAdapter da = new SqlDataAdapter(_cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public DataSet GetArticalName()
{
_conn = new SqlConnection(str);
_cmd = new SqlCommand( getarticlename ,_ conn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.CommandText = getarticlename;
SqlParameter p1 = null ;
p1 = new SqlParameter();
p1.ParameterName = @ articlename;
p1.Value = TMAST_HEAD_NAME;
_cmd.Parameters.Add(p1);
SqlDataAdapter da = new SqlDataAdapter(_cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlhead =(e.Row.FindControl( DropDownList1) as DropDownList);
DropDownList ddlartical =(e.Row.FindControl( DropDownList2) as DropDownList);
if (ddlhead!= null && ddlartical!= null )
{
ddlhead.DataSource = GetHeadName();
ddlhead.DataTextField = TMAST_HEAD_NAME;
ddlhead.DataValueField = TMAST_HEAD_NAME;
ddlhead.DataBind();
// 在DropDownList中添加默认项
ddlhead.Items.Insert( 0 , new ListItem( - 请选择headname - ));
ddlhead.SelectedValue = Gridview1.DataKeys [e.Row.RowIndex] .Values [ 0 ]。ToString();
ddlhead.DataSource = GetArticalName();
// ddlhead.DataTextField =TMAST_ARTICLE_NAME;
// ddlhead.DataValueField =TMAST_ARTICLE_NAME;
ddlhead.DataBind();
// 在DropDownList中添加默认项
ddlhead.Items.Insert( 0 , new ListItem( - 请选择artical - ));
// ddlhead.SelectedValue = Gridview1.DataKeys [e.Row.RowIndex] .Values [2]。 ToString();
}
}
else
{
ScriptManager.RegisterStartupScript( this , this .GetType(), script, alert('来源不可用');, true );
}
解决方案
Hai,
请试试这个链接它可以帮助你
http://stackoverflow.com/questions/7329224/how-to-bind-a-dropdownlist-in-gridview [ ^ ]
www.jobpencil.com [ ^ ]
I would like to bind two DropDownList into a GridView in ASP.NET.
I did bind one DropDownList with Databound event, but the problem is how can I bind the second DropDownList in the GridView?
my requirement is 1 dropdownlist selected autometically second dropdownlist bind i tied the below code its not working plz help me any one....
public DataSet GetHeadName()
{
_conn = new SqlConnection(str);
_cmd = new SqlCommand("getheadname", _conn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.CommandText = "getheadname";
SqlDataAdapter da = new SqlDataAdapter(_cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
public DataSet GetArticalName()
{
_conn = new SqlConnection(str);
_cmd = new SqlCommand("getarticlename", _conn);
_cmd.CommandType = CommandType.StoredProcedure;
_cmd.CommandText = "getarticlename";
SqlParameter p1 = null;
p1 = new SqlParameter();
p1.ParameterName = "@articlename";
p1.Value = "TMAST_HEAD_NAME";
_cmd.Parameters.Add(p1);
SqlDataAdapter da = new SqlDataAdapter(_cmd);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddlhead = (e.Row.FindControl("DropDownList1") as DropDownList);
DropDownList ddlartical = (e.Row.FindControl("DropDownList2") as DropDownList);
if (ddlhead != null && ddlartical != null)
{
ddlhead.DataSource = GetHeadName();
ddlhead.DataTextField = "TMAST_HEAD_NAME";
ddlhead.DataValueField = "TMAST_HEAD_NAME";
ddlhead.DataBind();
//Add Default Item in the DropDownList
ddlhead.Items.Insert(0, new ListItem("--please select headname--"));
ddlhead.SelectedValue = Gridview1.DataKeys[e.Row.RowIndex].Values[0].ToString();
ddlhead.DataSource = GetArticalName();
//ddlhead.DataTextField = "TMAST_ARTICLE_NAME";
//ddlhead.DataValueField = "TMAST_ARTICLE_NAME";
ddlhead.DataBind();
//Add Default Item in the DropDownList
ddlhead.Items.Insert(0, new ListItem("--please select artical--"));
// ddlhead.SelectedValue = Gridview1.DataKeys[e.Row.RowIndex].Values[2].ToString();
}
}
else
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "script", "alert('Source Not Available');", true);
}
解决方案
Hai,
please try this link it may help you
http://stackoverflow.com/questions/7329224/how-to-bind-a-dropdownlist-in-gridview[^]
www.jobpencil.com[^]
这篇关于我想将2下拉列表绑定到网格视图中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文