繁体   English   中英

在Gridview中的下拉列表

[英]Drop Down List In A Gridview

我有一个GridView ,里面GridView我有一个模板领域和内部的,一个下拉列表中。

<asp:TemplateField>
    <ItemTemplate>
        <asp:DropDownList ID="Hello" runat="server">
        </asp:DropDownList>
    </ItemTemplate>
</asp:TemplateField>

我想对GridView进行数据绑定,但是如何使下拉列表根据数据绑定时提供的信息将其值更改为?

我曾经在绑定字段中使用DataField

<asp:BoundField HeaderText="Hello" DataField="HelloDB" />

您所要做的只是点击GridViewOnRowDataBind事件。 在其中,您可以使用FindControl()获取下拉列表,将其DropDownDropDown ,然后设置值。

当每一行都是数据绑定时,将调用此事件,因此每个下拉列表都会被更新。

Microsoft为此提供了一个演练

Bing快速搜索附带了许多其他文章和操作方法。

例:

protected void MethodName(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
{
if (e.Row.RowType == System.Web.UI.WebControls.DataControlRowType.DataRow)
    {
     DropDownList Hello = e.Row.FindControl("Hello") as DropDownList;
     //here you can bind the dropdown list.

    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM