Go homepage(回首页)
Upload pictures (上传图片)
Write articles (发文字帖)

The author:(作者)delv
published in(发表于) 2014/1/24 9:08:28
ASP.NE技巧:GridView绑定DropdownList_[Asp.Net教程]

ASP.NE技巧:GridView绑定DropdownList_[Asp.Net教程]

绑定下拉菜单,显示的时候是一个label,在点编辑的时候才显示出下拉菜单来


html代码部分:










CS代码部分



protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList goodsType = (DropDownList)e.Row.FindControl("DropDownList1");
if (goodsType != null)
{
con = new SqlConnection(ConfigurationManager.ConnectionStrings["TestProviderConnectionString"].ConnectionString);
DataSet ds = new DataSet();
SqlDataAdapter da = new SqlDataAdapter("select * from goodsType",con);
da.Fill(ds,"gt");
goodsType.DataSource = ds.Tables["gt"];
goodsType.DataTextField = "goodsType";
goodsType.DataValueField = "goodsId";
goodsType.DataBind();
}
}







If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)





QQ:154298438
QQ:417480759