GridView里怎么放DropDownList
前台<asp:BoundFieldDataField="CID"HeaderText="编号"ReadOnly="True"/><asp:TemplateFieldHea...
前台
<asp:BoundField DataField="CID" HeaderText="编号" ReadOnly="True" />
<asp:TemplateField HeaderText="品牌">
<AlternatingItemTemplate>
<asp:HiddenField ID="HDFXueli" runat="server" Value='<%# Eval("BName") %>' />
<asp:DropDownList ID="dropDown" runat="server">
</asp:DropDownList>
</AlternatingItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
后台
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (((DropDownList)e.Row.FindControl("dropDown")) != null)
{
DropDownList dropDown = (DropDownList)e.Row.FindControl("dropDown");
string sql = "select distinct(BName) from Brand";
DataTable data = (DataTable)BrandManager.lianDong(sql);
dropDown.DataTextField = "BName";
dropDown.DataValueField = "BName";
dropDown.DataSource = data;
dropDown.DataBind();
dropDown.DataValueField = "BName";
// 选中 DropDownList
dropDown.SelectedValue = ((HiddenField)e.Row.FindControl("HDFXueli")).Value;
//
}
}
不知道为什么只有每页第二行和第四行有DropDownList,
而其他行没有!
请高手帮帮忙!
谢谢了! 展开
<asp:BoundField DataField="CID" HeaderText="编号" ReadOnly="True" />
<asp:TemplateField HeaderText="品牌">
<AlternatingItemTemplate>
<asp:HiddenField ID="HDFXueli" runat="server" Value='<%# Eval("BName") %>' />
<asp:DropDownList ID="dropDown" runat="server">
</asp:DropDownList>
</AlternatingItemTemplate>
<ItemStyle Width="100px" />
</asp:TemplateField>
后台
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (((DropDownList)e.Row.FindControl("dropDown")) != null)
{
DropDownList dropDown = (DropDownList)e.Row.FindControl("dropDown");
string sql = "select distinct(BName) from Brand";
DataTable data = (DataTable)BrandManager.lianDong(sql);
dropDown.DataTextField = "BName";
dropDown.DataValueField = "BName";
dropDown.DataSource = data;
dropDown.DataBind();
dropDown.DataValueField = "BName";
// 选中 DropDownList
dropDown.SelectedValue = ((HiddenField)e.Row.FindControl("HDFXueli")).Value;
//
}
}
不知道为什么只有每页第二行和第四行有DropDownList,
而其他行没有!
请高手帮帮忙!
谢谢了! 展开
3个回答
展开全部
编辑项-添加模版项-编辑模版,把dropdownlist拖进去
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
把AlternatingItemTemplate换成ItemTemplete
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那你就写 项模板和交替模板都写上daopdownlist啊
你试试看啦
你试试看啦
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询