HTML
<!--Add other attributes as you need to the grid view-->
<!--NOTE: **OnRowDataBound="GridView_RowDataBound"** -->
<asp:GridView ID="GridView1" runat="server"
OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="Dropdown Column">
<ItemTemplate>
<asp:DropDownList ID="ddlYesNo" runat="server">
<asp:ListItem Value="1" Text="No"></asp:ListItem>
<asp:ListItem Value="2" Text="Yes"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<!-- OTHER COLUMNS -->
</Columns>
<!-- REST OF THE STUFF -->
CODE BEHIND
protected void GridView1_RowDataBound(Object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
DropDownList ddl = (DropDownList)e.Row.FindControl("ddlYesNo");
ddl.SelectedValue =
((System.Data.DataRowView)e.Row.DataItem) ["dataColName"].ToString();
}
}
出典
2012-03-18 15:28:20
Kaf
利用のselectedIndex = 1がyesの値を表示します。 – Sas
私は試しました、働かなかった –
うん、それは今どのように私は値を保存することができましたか?アップデート時に何かを選択すると、ドロップダウンで値が選択されます –