2010-07-05 86 views
2

我有一個顯示用戶列表和角色列表的中繼器。還有一個下拉列表chnage有作用見下文從中繼器內的下拉列表更新用戶角色

<td><asp:DropDownList ID="ddlChangeType" class="controlwidth100" runat="server" AutoPostBack="true" OnSelectedIndexChanged="change" /></td> 

更改事件的作品,但我需要的是該行的ID,因此用戶可以更新。

回答

1

它仍然暴露在客戶端上的用戶名,但是這應該讓你有:

<td><asp:DropDownList ID="ddlChangeType" class="controlwidth100" runat="server" AutoPostBack="true" OnSelectedIndexChanged="change" UserID=<%#Eval("UserID") %> /></td> 

和服務器事件:

Protected Sub change(ByVal sender As Object, ByVal e As EventArgs) 
    Response.Write(DirectCast(sender, DropDownList).Attributes("UserID")) 
End Sub 
0

一個選擇是在GridView中使用其內置的編輯功能。我通常不會建議GridView控件,但是我在這裏做,因爲從您輸入的標記中可以清楚地看出您正在渲染一張表。

另一種選擇是將其作爲AJAX調用,通過Javascript獲取行值。無論如何,這可能比完整的回傳表現要好一些。

0
<td> 
    <asp:DropDownList ID="ddlChangeType" class="controlwidth100" 
     runat="server" AutoPostBack="true" OnSelectedIndexChanged="change" /> 
    <asp:HiddenField ID="RoleIdValue" runat="server" 
     Value='<$# Databinder.Eval(Container.DataItem, "UserId") %>' /> 
     //Set the userId here so you can access it from code 
</td> 

protected void change(object sender, EventArgs e) { 
    DropDownList ddlChangeType = (DropDownList)sender; 
    HiddenField RoleIdValue = 
     (HiddenField)ddlChangeType.Parent.FindControl("RoleIdValue"); 

    string? userId = RoleIdValue.Value; 
    string? roleId = ddlChangeType.SelectedValue; 
    SomeDS.Update(userId, roleId); 
} 
相關問題