Refer to

http://samples.gotdotnet.com/quickstart/aspplus/doc/webdataaccess.aspx

Look for VBDataGrid8.aspx

- Subramanya K Vemuri-Venkata





----- Original Message ----- 
From: "Harry" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, May 21, 2004 10:49 AM
Subject: [AspNetAnyQuestionIsOk] Dynamic DropDownList VB.NET (Source 
Attached)


> Hi,
>
> I am having this BIG problem....Any help will be
> greatly appreciated. Please find all my code attached
> below.
>
> The problem is within a DataGrid I have a "EDIT" link
> which changes certain items into TextBox control. I
> would like them to be changed into a Database bound
> DropDownList control once "Edit" is clicked. how can i
> do that.
>
> Any help will be greatly appreciated.
>
> Thanks,
>
>
> <%@ Page debug="true" %>
> <%@ Import namespace="System.Data.OleDb" %>
> <%@ Import namespace="System.Data" %>
> <HTML>
> <HEAD>
> <title>Updating Requests</title>
> </HEAD>
> <body>
> <form id="Form1" method="post" runat="server">
> <P>
> <TABLE id="Table1" cellSpacing="1" cellPadding="1"
> width="664" border="0">
> <TR>
> <TD width="289" bgColor="tan"><IMG
> src="logo.gif"></TD>
> <TD bgColor="tan"><FONT
> face="Arial"><STRONG>Inflow Disaster Recovery-
> Grant/Modify Access</STRONG></FONT></TD>
> </TR>
> </TABLE>
> </P>
> <P><asp:datagrid id="dgInflow" runat="server"
> CellPadding="1" AutoGenerateColumns="False"
> OnEditCommand="EditRecord"
> OnCancelCommand="CancelEdit"
> OnUpdateCommand="Updaterecord" Font-Names="Arial"
> Font-Size="XX-Small"
> Width="664px">
> <HeaderStyle BackColor="Tan"></HeaderStyle>
> <AlternatingItemStyle
> BackColor="Khaki"></AlternatingItemStyle>
> <ItemStyle Font-Size="XX-Small"
> Font-Names="Arial"></ItemStyle>
> <Columns>
> <asp:BoundColumn Visible="False" DataField="ID"
> ReadOnly="True"></asp:BoundColumn>
> <asp:BoundColumn DataField="RequestTimeStamp"
> ReadOnly="True" HeaderText="Request Time
> Stamp"></asp:BoundColumn>
> <asp:BoundColumn DataField="RequestorName"
> ReadOnly="True" HeaderText="Requestor
> Name"></asp:BoundColumn>
> <asp:BoundColumn DataField="RequesteeName"
> ReadOnly="True" HeaderText="Requestee
> Name"></asp:BoundColumn>
> <asp:BoundColumn DataField="RackAccessAuthority"
> ReadOnly="True" HeaderText="Rack Access
> Authority"></asp:BoundColumn>
> <asp:BoundColumn DataField="AccessStatus"
> HeaderText="Access Status"></asp:BoundColumn>
> <asp:BoundColumn
> DataField="AdministrativeDecision"
> HeaderText="Administrative
> Decision"></asp:BoundColumn>
> <asp:BoundColumn
> DataField="AdministrativeReason"
> HeaderText="Administrative Reason"></asp:BoundColumn>
> <asp:EditCommandColumn ButtonType="LinkButton"
> UpdateText="Save" CancelText="Cancel"
> EditText="Edit"></asp:EditCommandColumn>
> </Columns>
> </asp:datagrid></P>
> </form>
> <script language="VB" runat="server">
> 'Private strConnection As String =
> "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
> Server.MapPath("ic.mdb")
> Private strSQLSelect As String = "SELECT i.ID,
> i.RequestTimeStamp, tt1.RequestorName,
> tt2.RequesteeName, i.RackAccessAuthority,
> i.AccessStatus, i.AdministrativeDecision,
> i.AdministrativeReason FROM Inflow AS i, [SELECT
> i1.id,p1.ITSM_PERSONS_PER_NAME  as RequestorName  from
> Inflow i1 left join  persons p1 on
> p1.ITSM_PERSONS_PER_OID = i1.RequestorperOID]. AS tt1,
> [SELECT i2.id,p2.ITSM_PERSONS_PER_NAME as
> RequesteeName  from Inflow i2 left join  persons p2 on
>  p2.ITSM_PERSONS_PER_OID = i2.RequesteeperOID]. AS tt2
> WHERE (((i.ID)=[tt1].[id] And (i.ID)=[tt2].[id]))"
> Private InflowTableName As String = "InflowTable"
> Private objConnection As OleDbConnection
>
> Private Sub Page_Load(ByVal Sender As Object, ByVal E
> As EventArgs)
>   If Not IsPostBack Then
>     LoadGrid()
>   End If
> End Sub
>
> Private Sub LoadGrid()
>   Connect()
>   Dim adapter As New OleDbDataAdapter(strSQLSelect,
> objConnection)
>   Dim ds As New DataSet()
>   adapter.Fill(ds, InflowTableName)
>   Disconnect()
>
>   dgInflow.DataSource = ds.Tables(InflowTableName)
>   dgInflow.DataBind()
> End Sub
>
> Private Sub Connect()
>   If objConnection Is Nothing Then
>     objConnection = New
> OleDbConnection(ConfigurationSettings.AppSettings("strConnection"))
>   End If
>
>   If objConnection.State = ConnectionState.Closed Then
>     objConnection.Open()
>   End If
> End Sub
>
> Private Sub Disconnect()
>   objConnection.Close()
> End Sub
>
> Public Sub EditRecord(ByVal Sender As Object, _
>                       ByVal E As
> DataGridCommandEventArgs)
>   dgInflow.EditItemIndex = E.Item.ItemIndex
>   LoadGrid()
> End Sub
>
> Public Sub CancelEdit(ByVal Sender As Object, _
>                       ByVal E As
> DataGridCommandEventArgs)
>   dgInflow.EditItemIndex = -1
>   LoadGrid()
> End Sub
>
> Public Sub UpdateRecord(ByVal Sender As Object, _
>                         ByVal E As
> DataGridCommandEventArgs)
>
>   'Retrieve the field values in the edited row
>   Dim ID As Int32 =
> Convert.ToInt32(E.Item.Cells(0).Text)
>   Dim AccessStatusTextBox As TextBox =
> CType(E.Item.Cells(5).Controls(0), TextBox)
>   Dim AccessStatus As String =
> Convert.ToString(AccessStatusTextBox.Text)
>   Dim AdministrativeDecisionTextBox As TextBox =
> CType(E.Item.Cells(6).Controls(0), TextBox)
>   Dim AdministrativeDecision As String =
> Convert.ToString(AdministrativeDecisionTextBox.Text)
>   Dim AdministrativeReasonTextBox As TextBox =
> CType(E.Item.Cells(7).Controls(0), TextBox)
>   Dim AdministrativeReason As String =
> Convert.ToString(AdministrativeReasonTextBox.Text)
>
>   dgInflow.EditItemIndex = -1
>   UpdateProduct(ID, AccessStatus,
> AdministrativeDecision, AdministrativeReason)
> End Sub
>
> Private Sub UpdateProduct(ByVal ID As Long, ByVal
> AccessStatus As String, AdministrativeDecision As
> String, AdministrativeReason As String)
>
>   'Create and load a DataSet with records from Inflow
> table
>   Connect()
>   Dim adapter As New OleDbDataAdapter(strSQLSelect,
> objConnection)
>   Dim ds As New DataSet()
>   adapter.Fill(ds, InflowTableName)
>   Disconnect()
>
>   'Modify the in-memory records in the DataSet
>   Dim tbl As DataTable = ds.Tables(InflowTableName)
>   tbl.PrimaryKey = New DataColumn() _
>                    { _
>                      tbl.Columns("ID") _
>                    }
>   Dim row As DataRow = tbl.Rows.Find(ID)
>   row.Item("AccessStatus") = AccessStatus
>   row.Item("AdministrativeDecision") =
> AdministrativeDecision
>   row.Item("AdministrativeReason") =
> AdministrativeReason
>
>   'Reconnect the DataSet and update the database
>   Dim cb As New OleDbCommandBuilder(adapter)
>   Connect()
>
>   Dim strSQLUpdate As String = "UPDATE Inflow SET
> AccessStatus = '" & row.Item("AccessStatus") & "',
> AdministrativeDecision = '" &
> row.Item("AdministrativeDecision") & "',
> AdministrativeReason = '" &
> row.Item("AdministrativeReason") & "' WHERE ID=" &
> row.Item("ID") & ""
>
>     Dim dbComm As OleDbCommand = New
> OleDbCommand(strSQLUpdate, objConnection)
>     'Response.Write(strSQLUpdate)
>     Try
>       dbComm.ExecuteNonQuery()
>     Catch ex As Exception
>       Response.Write(ex.Message)
>       Response.End
>     Finally
>   Disconnect()
>     End Try
>
>   dgInflow.DataSource = ds.Tables(InflowTableName)
>   dgInflow.DataBind()
> End Sub
> </script>
> </body>
> </HTML>
>
>
>
>
>
>
>
>
> __________________________________
> Do you Yahoo!?
> Yahoo! Domains  Claim yours for only $14.70/year
> http://smallbusiness.promotions.yahoo.com/offer
>
>
>
> Yahoo! Groups Links
>
>
>
>
>
> 


 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
     http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
     [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
     http://docs.yahoo.com/info/terms/
 

Reply via email to