1

我们将 ASP.NET 用于我们的一个项目。然而,当我们试图读取我们在链接点击的回调函数中使用的 DropDownList 的 SelectedItem 或 SelectedValue 属性时,我们没有得到正确的 SelectedItem。

<FooterTemplate>
<asp:DropDownList ID="cmbTesters" ClientIDMode="Static" runat="server" Width="300px" DataSource='<%# PopulateTesterNames() %>' DataTextField="FullName" DataValueField = "PK_ID"></asp:DropDownList>
</FooterTemplate>

这是 aspx 文件中的 DropDownList。下拉菜单出现在 GridView 的页脚行中。我们在单击链接时调用以下代码集。

  if (int.TryParse(((DropDownList)dgCreateCPRVerificationResponse.FooterRow.FindControl("cmbTesters")).SelectedValue, out TesterID))
  {
   TesterID = int.Parse(((DropDownList)dgCreateCPRVerificationResponse.FooterRow.FindControl("cmbTesters")).SelectedValue);
  }

我们面临的问题是,无论我们选择什么值,SelectedValue 始终是列表中的第一项。我们正在使用 global.asax 文件中定义的基于 REST 的 URL。另请注意,这不是建立在任何框架上的。

请尽快提供帮助

4

1 回答 1

0

确保将下拉列表和gridview的绑定方法放在里面if (!IsPostBack)

于 2012-04-05T13:46:06.653 回答