当 DropDownList "eventnoteEditDrpDwnLst" 的值设置为 "Custom..." 时,我想在 GridView 中将 "Visible = true" 设置为 TextBox "eventnoteAddTextBox"
<asp:GridView ID="grid" runat="server"
...
OnRowCommand="grid_RowCommand"
ShowFooter="True">
<columns>
...
<asp:TemplateField HeaderText="Event">
<ItemTemplate>
<asp:Label ID="eventnoteLbl" runat="server" Text='<%# Bind("eventnote") %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="eventnoteEditDrpDwnLst" runat="server" DataTextField="eventnote" DataValueField="eventnote"></asp:DropDownList>
</EditItemTemplate>
<FooterTemplate>
<asp:DropDownList ID="eventnoteAddDrpDwnLst" runat="server" DataTextField="eventnote" DataValueField="eventnote" CommandName="AddCustomEventNote" CommandArgument="<%# ??? eventnoteAddDrpDwnLst.SelectedText ??? %>"></asp:DropDownList>
<asp:UpdatePanel ID="eventnoteAddUpdatePanel" runat="server" RenderMode="Block">
<ContentTemplate>
<asp:TextBox ID="eventnoteAddTextBox" runat="server" DataTextField="eventnote" DataValueField="eventnote" Visible="False"></asp:TextBox>
</ContentTemplate>
</asp:UpdatePanel>
</FooterTemplate>
</asp:TemplateField>
...
</columns>
</asp:GridView>
代码隐藏
protected void grid_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("AddCustomEventNote"))
{
DropDownList eventnoteAddDrpDwnLst = (DropDownList)e.CommandSource;
if (eventnoteAddDrpDwnLst.SelectedValue == "Custom...")
Response.Write("<script>alert('It works!');</script>");
//grid.FooterRow.FindControl("eventnoteAddTextBox").Visible = true;
}
}
这行不通。