扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:佚名 来源:Microsoft 2007年11月8日
关键字: Windows
<asp:DataGrid id="DataGrid1" runat="server" CssClass="grid" AutoGenerateColumns="False"> <Columns> <asp:EditCommandColumn EditText="Edit" CancelText="Cancel" UpdateText="Update" /> <asp:BoundColumn DataField="OrderID" ReadOnly="True" HeaderText="Order ID" /> <asp:BoundColumn DataField="ShipName" HeaderText="Ship to" ReadOnly="True" /> <asp:BoundColumn DataField="ShipCountry" HeaderText="Country" ReadOnly="True" /> <asp:TemplateColumn HeaderText="Ship Method"> <ItemTemplate> <%#Container.DataItem("ShipVia")%> </ItemTemplate> <EditItemTemplate> <asp:DropDownList runat="server" ID="Dropdownlist1"/> </EditItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> |
Sub BindGrid() Dim SQL As String = "SELECT OrderID, ShipName, ShipCountry, ShipVia FROM Orders" Dim DA As SqlDataAdapter = New SqlDataAdapter(SQL, ConnStr) Dim DS As New DataSet DA.Fill(DS, "Orders") DataGrid1.DataSource = DS.Tables("Orders").DefaultView DataGrid1.DataBind() 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 DRV As DataRowView = CType(e.Item.DataItem, DataRowView) Dim CurrentShip As String = DRV("ShipVia") Dim DDL As DropDownList = CType(e.Item.Cells(4).Controls(1), DropDownList) Dim SQL As String = "SELECT ShipperID, CompanyName FROM Shippers ORDER BY ShipperID" Dim DA As SqlDataAdapter = New SqlDataAdapter(SQL, ConnStr) Dim DS As New DataSet Dim item As ListItem DA.Fill(DS, "Shippers") DDL.DataSource = DS.Tables("Shippers").DefaultView DDL.DataTextField = "CompanyName" DDL.DataValueField = "ShipperID" DDL.DataBind() item = DDL.Items.FindByValue(CurrentShip) If Not item Is Nothing Then item.Selected = True End If End Sub |
Private Sub DataGrid1_UpdateCommand(ByVal source As Object, _ ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _ Handles DataGrid1.UpdateCommand Dim DDL As DropDownList = CType(e.Item.Cells(4).Controls(1), DropDownList) Dim NewShip As Integer = DDL.SelectedValue Dim OrderID As Integer = Int32.Parse(e.Item.Cells(1).Text) Dim SQL As String = "UPDATE Orders SET ShipVia=@Ship WHERE OrderID=@ID" Dim Conn As SqlConnection = New SqlConnection(ConnStr) Dim Cmd As New SqlCommand(SQL, Conn) Cmd.Parameters.Add(New SqlParameter("@Ship", NewShip)) Cmd.Parameters.Add(New SqlParameter("@ID", OrderID)) Conn.Open() Cmd.ExecuteNonQuery() Conn.Close() DataGrid1.EditItemIndex = -1 BindGrid() End Sub |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者