【问题标题】:ASP INLINE dropdownlist box in Gridview Edit TemplateGridview 编辑模板中的 ASP INLINE 下拉列表框
【发布时间】:2012-12-13 22:12:22
【问题描述】:

我正在尝试将下拉列表框编码到 gridview 的编辑模板中。我有所有的工作。我不知道如何将下拉列表框中的值返回到 Gridview,以便更新按钮将返回。

我需要使用 ASP 内联代码来执行此操作,而不是页面后面的代码。我已将 gridview 中的字段转换为 Templatefield。

这是我目前所拥有的,但我一直在改变以尝试其他东西......

<asp:TemplateField HeaderText="Vehicle ID" SortExpression="tractorID"> 
 <EditItemTemplate> 
    <asp:DropDownList ID="DropDownList7" runat="server"  Width="70px" DataValueField="Value" 
                      SelectedValue='<%# Bind("tractorID") %>' DataSourceID="SqlDataSource1"  /> 
 </EditItemTemplate> 
 <ItemTemplate> 
    <asp:Label ID="Label1" runat="server" Text='<%# Eval("tractorID") %>'></asp:Label> 
 </ItemTemplate> 
</asp:TemplateField>

【问题讨论】:

    标签: asp.net vb.net gridview


    【解决方案1】:

    这是完成工作的正确代码。我无法找出 INLINE 解决方案,不得不将其添加到 RowDataBound 事件中。

    ' gets value of originally loaded record.
    Dim vehID = row.Field(Of Integer)("tractorID") 
    '  finds the dropdownlist to add the value to.
    Dim tractorDDL As DropDownList = DirectCast(e.Row.FindControl("DropDownlist7"), DropDownList)
    ' Adds the value to the ddl
    tractorDDL.Items.Add(vehID )      '  Adds value of the original record
    

    完美运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-11-26
      • 2014-10-04
      • 2011-05-10
      • 1970-01-01
      相关资源
      最近更新 更多