Html代码
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 184px"
runat="server" AutoGenerateColumns="False" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Horizontal"> <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle> <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle> <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle> <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle> <Columns>
<asp:TemplateColumn HeaderText="111">
<EditItemTemplate>
<asp:DropDownList ID="d" Runat="server"></asp:DropDownList> </EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Stringvalue" HeaderText="Stringvalue"></asp:BoundColumn> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle> </asp:DataGrid>
</form>
<form id="Form1" method="post" runat="server">
<asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 224px; POSITION: absolute; TOP: 184px"
runat="server" AutoGenerateColumns="False" BorderColor="#E7E7FF" BorderStyle="None" BorderWidth="1px"
BackColor="White" CellPadding="3" GridLines="Horizontal"> <SelectedItemStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#738A9C"></SelectedItemStyle> <AlternatingItemStyle BackColor="#F7F7F7"></AlternatingItemStyle> <ItemStyle ForeColor="#4A3C8C" BackColor="#E7E7FF"></ItemStyle> <HeaderStyle Font-Bold="True" ForeColor="#F7F7F7" BackColor="#4A3C8C"></HeaderStyle> <FooterStyle ForeColor="#4A3C8C" BackColor="#B5C7DE"></FooterStyle> <Columns>
<asp:TemplateColumn HeaderText="111">
<EditItemTemplate>
<asp:DropDownList ID="d" Runat="server"></asp:DropDownList> </EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="Stringvalue" HeaderText="Stringvalue"></asp:BoundColumn> <asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" HeaderText="Edit" CancelText="Cancel"
EditText="Edit"></asp:EditCommandColumn>
</Columns>
<PagerStyle HorizontalAlign="Right" ForeColor="#4A3C8C" BackColor="#E7E7FF" Mode="NumericPages"></PagerStyle> </asp:DataGrid>
</form>
后台代码 .VB
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
bind()
End If
End Sub
Dim d As New Data
DataGrid1.DataSource = d.CreateDataSource()
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
bind()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim d1 As New DropDownList
Dim d As New Data
d1 = CType(e.Item.FindControl("d"), DropDownList)
d1.DataSource = d.CreateDataSource()
d1.DataTextField = "Stringvalue"
d1.DatavalueField = "Integervalue"
d1.DataBind()
End If
End Sub
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not IsPostBack Then
bind()
End If
End Sub
Dim d As New Data
DataGrid1.DataSource = d.CreateDataSource()
DataGrid1.DataBind()
End Sub
Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles DataGrid1.EditCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
bind()
End Sub
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound
If e.Item.ItemType = ListItemType.EditItem Then
Dim d1 As New DropDownList
Dim d As New Data
d1 = CType(e.Item.FindControl("d"), DropDownList)
d1.DataSource = d.CreateDataSource()
d1.DataTextField = "Stringvalue"
d1.DatavalueField = "Integervalue"
d1.DataBind()
End If
End Sub
C#代码
private void Page_Load(object sender, System.EventArgs e)
{
if (!(IsPostBack)) {
bind();
}
}
void bind()
{
Data d = new Data();
DataGrid1.DataSource = d.CreateDataSource();
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
bind();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem) {
DropDownList d1 = new DropDownList();
Data d = new Data();
d1 = ((DropDownList)(e.Item.FindControl("d")));
d1.DataSource = d.CreateDataSource();
d1.DataTextField = "Stringvalue";
d1.DatavalueField = "Integervalue";
d1.DataBind();
}
}
private void Page_Load(object sender, System.EventArgs e)
{
if (!(IsPostBack)) {
bind();
}
}
void bind()
{
Data d = new Data();
DataGrid1.DataSource = d.CreateDataSource();
DataGrid1.DataBind();
}
private void DataGrid1_EditCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
DataGrid1.EditItemIndex = e.Item.ItemIndex;
bind();
}
private void DataGrid1_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.EditItem) {
DropDownList d1 = new DropDownList();
Data d = new Data();
d1 = ((DropDownList)(e.Item.FindControl("d")));
d1.DataSource = d.CreateDataSource();
d1.DataTextField = "Stringvalue";
d1.DatavalueField = "Integervalue";
d1.DataBind();
}
}