更新时间:2023-02-11 19:43:09
您可以使用bind绑定数据库中的值
示例如下:
< pre lang ="c#">
< asp:TemplateField HeaderText ="Status" ItemStyle-Width ="100px">
< ItemTemplate>
< asp:DropDownList ID ="DropDownList1" runat ="server" SelectedValue =''<%#Bind("STATUS")%>''
Enabled ="false">
< asp:ListItem Text ="Active" Value ="1"></asp:ListItem>
< asp:ListItem Text =无效" Value ="0"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
< EditItemTemplate>
< asp:DropDownList ID ="DropDownList1" runat ="server" SelectedValue =''<%#Bind("STATUS")%>''>
< asp:ListItem Text ="Active" Value ="1"></asp:ListItem>
< asp:ListItem Text =无效" Value ="0"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
< ItemStyle Width ="100px"></ItemStyle>
</asp:TemplateField></pre>
You can use bind to bind a value from database
example is given below:
<pre lang="c#">
<asp:TemplateField HeaderText="Status" ItemStyle-Width="100px">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%# Bind("STATUS")%>''
Enabled="false">
<asp:ListItem Text="Active" Value="1"></asp:ListItem>
<asp:ListItem Text="Inactive" Value="0"></asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" SelectedValue=''<%# Bind("STATUS")%>''>
<asp:ListItem Text="Active" Value="1"></asp:ListItem>
<asp:ListItem Text="Inactive" Value="0"></asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
<ItemStyle Width="100px"></ItemStyle>
</asp:TemplateField></pre>
这非常简单.您将所选项目猫"保留在临时存储架中.在PageLoad事件上,设置GridView类的SelecteIndex属性.有关更多详细信息,请转到 http://msdn.microsoft. com/en-us/library/system.web.ui.webcontrols.gridview.selectedindex.aspx [
Itz pretty simple. You keep the selected item ''Cat'' in temporary storage holder. On PageLoad event, set the SelecteIndex property of GridView class. For further details, go thro http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.selectedindex.aspx[^]