如何设置datagrid中的DropDownList显示的是绑定记录的当前数据?
gqxm 2003-08-25 11:11:16 datagrid中包含一个EditItemTemplate是DropDownList的列,现我想在点击编辑时,DropDownList显示的是绑定记录的当前数据,而不是DropDownList的第一条数据,请问语句应如何写?
datagrid代码:
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 8px" runat="server" CssClass="f9black" BackColor="White" ForeColor="Black" Width="200px" Height="256px" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px" CellPadding="4" GridLines="Vertical" AutoGenerateColumns="False" DataKeyField="id">
<SelectedItemStyle Font-Bold="True" ForeColor="White" BackColor="#CE5D5A"></SelectedItemStyle>
<AlternatingItemStyle BackColor="White"></AlternatingItemStyle>
<ItemStyle BackColor="#F7F7DE"></ItemStyle>
<HeaderStyle Font-Bold="True" ForeColor="White" BackColor="#6B696B"></HeaderStyle>
<FooterStyle BackColor="#CCCC99"></FooterStyle>
<Columns>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="确定" CancelText="取消" EditText="编辑">
<HeaderStyle Width="20px"></HeaderStyle>
<ItemStyle Font-Size="Small"></ItemStyle>
</asp:EditCommandColumn>
<asp:BoundColumn Visible="False" DataField="id" HeaderText="序号"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="排序序号">
<HeaderStyle Width="138px"></HeaderStyle>
<ItemTemplate>
<asp:Label id=Label8 runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.序号") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="DropDownList1" runat="server">
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="Black" BackColor="#F7F7DE" Mode="NumericPages"></PagerStyle>
</asp:DataGrid>
另外,如果我想把这个DropDownList1禁用,为什么以下语句不可以实现,DropDownList0是nothing。
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = CInt(e.Item.ItemIndex)
Dim DropDownList0 As DropDownList = CType(e.Item.FindControl("DropDownList1"), DropDownList)
DropDownList0.Enabled = False
bindgrid()
End Sub