当您使用下拉列表订购商品时,我想创建 Sharepoint 提供的相同功能,如下例所示,但我想在 asp.net 中创建它。
示例:当列 Modified 被选择为第一个时,每个 dropdowlist 的值会使用 javascript 或 jquery 自动重新排序。任何人都知道我该怎么做?我对javascript没有太多经验,所以我正在寻求帮助。
这是我到目前为止所拥有的:
asp代码:
<asp:GridView ID="GridView1" runat="server" EnableModelValidation="True" AutoGenerateColumns="False"
BorderStyle="Solid" RowStyle-Width="1" RowStyle-BorderWidth="1" RowStyle-BorderColor="silver"
Width="100%" OnRowEditing="GridView1_RowEditing"
onrowcancelingedit="GridView1_RowCancelingEdit"
onrowdatabound="GridView1_RowDataBound" DataKeyNames="ID,LanguageID">
<Columns>
<asp:TemplateField HeaderText="Ranking" HeaderStyle-HorizontalAlign="Left" SortExpression="Ranking">
<EditItemTemplate>
<asp:TextBox ID="TextBox4" runat="server" Text='<%# Bind("Ranking") %>'></asp:TextBox>
<asp:DropDownList ID="ddlRanking" runat="server">
</asp:DropDownList>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("Ranking") %>'></asp:Label>
<asp:DropDownList ID="DropDownList3" runat="server">
</asp:DropDownList>
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left"></HeaderStyle>
</asp:TemplateField>
</Columns>
<RowStyle BorderColor="Silver" BorderWidth="1px" Width="1px"></RowStyle>
</asp:GridView>
后面的代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) {
if (e.Row.RowType == DataControlRowType.DataRow) {
DropDownList ddlLang = (DropDownList)e.Row.FindControl("Dropdownlist2");
if (ddlLang != null) {
LanguagesList lang = new LanguagesList();
ddlLang.DataSource = lang.GetAllByLanguageId();
ddlLang.DataTextField = "LanguageName";
ddlLang.DataValueField = "ID";
ddlLang.DataBind();
ddlLang.SelectedValue = GridView1.DataKeys[e.Row.RowIndex].Values[1].ToString();
//ddlLang.Items.FindByValue((Label)(e.Row.FindControl("Label3"))).Selected = true;
}
DropDownList ddlRanking = (DropDownList) e.Row.FindControl("Dropdownlist3");
if(ddlRanking !=null) {
Ranking(ddlRanking);
}
}
}
这是上面代码的结果: