0

我有一个中继器,它将发布一个用户名、他们的权限级别和一个删除按钮。权限级别假设位于下拉列表中。默认值假设是用户当前拥有的值。

IE

用户 A,访客

用户 B,组成员

用户 C,组管理员

更改这些最终将触发 sql 命令以在数据库中更改它们。但这不是问题,我知道该怎么做。

这些值来自转发器源。

ASP 代码:

  <asp:SqlDataSource ID="User_Repeater_Source" runat="server" ConnectionString="<%$ ConnectionStrings:app_migrationConnectionString  %>"
    SelectCommand="SELECT Membership.*, Users.Email, Users.Last_Name + ', ' + Users.First_Name + ' (' + Membership.User_ID + ')' as User_String FROM Membership INNER JOIN Users ON Users.User_ID = Membership.User_ID INNER JOIN Permission_Levels ON Permission_Levels.PID = Membership.PID WHERE GID = @GID">
    <SelectParameters>
      <asp:ControlParameter ControlID="Group" DefaultValue="-1" Name="GID" PropertyName="SelectedValue"
        Type="String" />
    </SelectParameters>
  </asp:SqlDataSource>
  <asp:SqlDataSource ID="User_PL_Source" runat="server" ConnectionString="<%$ ConnectionStrings:app_migrationConnectionString  %>"
    SelectCommand="SELECT * FROM Permission_Levels"></asp:SqlDataSource>

...

  <td>
    <div class="e_Title">
      Edit Group Permission:</div>
    <br />
    <asp:Repeater ID="User_Repeater" runat="server" DataSourceID="User_Repeater_Source">
      <HeaderTemplate>
        <table class="e_Repeater">
          <tr>
            <th>
              User:
            </th>
            <th>
              Permission Level:
            </th>
            <th>
              Remove User:
            </th>
          </tr>
      </HeaderTemplate>
      <ItemTemplate>
        <tr>
          <td>
            <a href='<%#"mailto:" + DataBinder.Eval(Container.DataItem, "Email") %>'>
              <%#DataBinder.Eval(Container.DataItem, "User_String" %></a>
          </td>
          <td>
            <asp:DropDownList ID="User_PL" runat="server" DataSourceID="User_PL_Source" DataTextField="Name"
              DataValueField="PID" AutoPostBack="true">
            </asp:DropDownList>
          </td>
          <td>
            <asp:Button ID="Submit_User_Remove" runat="server" Text="Remove Permission" OnCommand="Remove_User_Permission"
              CommandArgument='<%# Eval("AID")%>' />
          </td>
        </tr>
      </ItemTemplate>
      <FooterTemplate>
        </table>
      </FooterTemplate>
    </asp:Repeater>
  </td>

我希望将 PID 传递到下拉列表中并使其成为选定的选项

4

1 回答 1

0

首先,我相信您并不打算将这个 asp-classic 标记为 asp.net。没什么大不了的。

我建议使用OnItemDataBound. 像这样让你开始的东西:

protected void User_Repeater_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
    RepeaterItem item = (RepeaterItem)e.Item;
    if (item.ItemType == ListItemType.AlternatingItem || item.ItemType == ListItemType.Item)
    {
        DropDownList User_PL = (DropDownList)item.FindControl("User_PL");
        ... Set your value here -- consider adding a hidden element with the value you're trying to set it to and get the value the same was as we got the DropDownList
    }
}

或者,我相信您可以使用标记绑定到控件本身:

SelectedValue='<%# Eval("PID") %>'

祝你好运。

于 2013-01-23T15:53:15.243 回答