如何在asp.net中填充选定的下拉值

时间:2019-06-03 12:02:30

标签: c# asp.net dropdown

Selected下拉值正变为NULL,但是当我尝试填充文本时,我就能得到这些值。

HTML代码:

<div class="form-group">
  <label>Indent No <font class="star_color"> * </font> </label>
  <asp:TextBox ID="txtindentNo" runat="server" Class="form-control" 
  OnTextChanged="txtindentNo_TextChanged"></asp:TextBox>
</div>
 <div class="form-group">
 <label>Select Item <font class="star_color"> * </font> </label>
   <asp:DropDownList ID="ddlItem" runat="server" class="form-control" AutoPostBack="true" OnSelectedIndexChanged="ddlItem_SelectedIndexChanged">
  </asp:DropDownList>
</div>


  <asp:TemplateField HeaderText="Indent Number " ItemStyle-HorizontalAlign="center">
   <ItemTemplate>
     <asp:Label ID="lblIndentNo" runat="server" Text='<%#Eval("IndentNumber") %>' Font-Size="Small"></asp:Label>
   </ItemTemplate>
 </asp:TemplateField>
 <asp:TemplateField HeaderText="Item" ItemStyle-HorizontalAlign="Left">
   <ItemTemplate>
    <asp:Label ID="lblItem" runat="server" Text='<%#Eval("SeedItemNameEng") %>' Font-Size="Small"></asp:Label>
 <asp:HiddenField ID="hdnItem" runat="server" Value='<%# Bind("SeedItemID") %>' />
  </ItemTemplate>
 </asp:TemplateField>

代码:

txtindentNo.Text = ((Label)grdItems.Rows[IndexValue].FindControl("lblIndentNo")).Text.Trim();
ddlItem.SelectedValue = ((Label)grdItems.Rows[IndexValue].FindControl("lblItem")).Text.Trim();

0 个答案:

没有答案