Hello,
I am having a bit of difficulty sorting this one out.
I am using an editable datagrid example I found on the internet. It didn't employ a code behind so I seperated it out to it's respective .aspx and .vb pages, and made it a user control. It works great, except for the small detail that a few of the textboxes that are used when editing a row, I must make into dropdowns with preselected options. And, of course, I am at a loss.
Let me show you what I'm working with:
While the aspx is rather straight forward:
How in the heck (and of course I am as ametuer as they come) do I employ the use of a dropdown instead of a textbox for certain fields while also providing the dropdown options?
Thanks
I am having a bit of difficulty sorting this one out.
I am using an editable datagrid example I found on the internet. It didn't employ a code behind so I seperated it out to it's respective .aspx and .vb pages, and made it a user control. It works great, except for the small detail that a few of the textboxes that are used when editing a row, I must make into dropdowns with preselected options. And, of course, I am at a loss.
Let me show you what I'm working with:
VB.NET:
Imports System.Data.SQLClient
Public Class EditSchedule
Inherits System.Web.UI.UserControl
#Region " Web Form Designer Generated Code "
'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
End Sub
Protected WithEvents MyDataGrid As System.Web.UI.WebControls.DataGrid
Protected WithEvents Form1 As System.Web.UI.HtmlControls.HtmlForm
Protected WithEvents Label1 As System.Web.UI.WebControls.Label
'NOTE: The following placeholder declaration is required by the Web Form Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object
Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub
#End Region
Private _calModuleId As String
Public Property calModuleId()
Get
Return _calModuleId
End Get
Set(ByVal Value)
_calModuleId = Value
End Set
End Property
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If Not Page.IsPostBack Then
BindData()
End If
End Sub
Sub Item_Created(ByVal sender As Object, ByVal e As DataGridItemEventArgs)
End Sub
Sub MyDataGrid_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = e.Item.ItemIndex
BindData()
End Sub
Sub MyDataGrid_Cancel(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
MyDataGrid.EditItemIndex = -1
BindData()
End Sub
Sub MyDataGrid_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
Dim conn As SqlConnection
Dim MyCommand As SqlCommand
Dim MyCommand2 As SqlCommand
Dim strConn As String = "server=pharos;uid=XXX;pwd=XXX;database=DotNetNuke"
Dim txtEventName As TextBox = e.Item.Cells(2).Controls(0)
Dim txtEventDateBegin As TextBox = e.Item.Cells(3).Controls(0)
Dim txtEventTimeBegin As TextBox = e.Item.Cells(4).Controls(0)
Dim txtHomeAway As TextBox = e.Item.Cells(5).Controls(0)
Dim txtVarsityJV As TextBox = e.Item.Cells(6).Controls(0)
Dim txtOppWins As TextBox = e.Item.Cells(7).Controls(0)
Dim txtOppLosses As TextBox = e.Item.Cells(8).Controls(0)
Dim txtWinLossTie As TextBox = e.Item.Cells(9).Controls(0)
Dim strUpdateStmt As String
Dim strUpdateStmt2 As String
strUpdateStmt = " UPDATE dbo.AVCalendar_V SET" & _
" EventName =@Ename, EventDateBegin =@Edate, EventTimeBegin =@Etime " & _
" WHERE EventID =@EID"
strUpdateStmt2 = " UPDATE dbo.AVCalendar_V SET" & _
" HomeAway =@Ehome, VarsityJV =@Evars, OppWins =@Eoppwins, OppLosses =@Eopplosses, WinLossTie =@Ewinloss WHERE EventID = @EID"
conn = New SqlConnection(strConn)
MyCommand = New SqlCommand(strUpdateStmt, conn)
MyCommand2 = New SqlCommand(strUpdateStmt2, conn)
MyCommand.Parameters.Add(New SqlParameter("@Ename", txtEventName.Text))
MyCommand.Parameters.Add(New SqlParameter("@Edate", txtEventDateBegin.Text))
MyCommand.Parameters.Add(New SqlParameter("@Etime", txtEventTimeBegin.Text))
MyCommand.Parameters.Add(New SqlParameter("@EID", e.Item.Cells(1).Text))
MyCommand2.Parameters.Add(New SqlParameter("@Ehome", txtHomeAway.Text))
MyCommand2.Parameters.Add(New SqlParameter("@Evars", txtVarsityJV.Text))
MyCommand2.Parameters.Add(New SqlParameter("@Eoppwins", txtOppWins.Text))
MyCommand2.Parameters.Add(New SqlParameter("@Eopplosses", txtOppLosses.Text))
MyCommand2.Parameters.Add(New SqlParameter("@Ewinloss", txtWinLossTie.Text))
MyCommand2.Parameters.Add(New SqlParameter("@EID", e.Item.Cells(1).Text))
conn.Open()
MyCommand.ExecuteNonQuery()
MyCommand2.ExecuteNonQuery()
MyDataGrid.EditItemIndex = -1
conn.Close()
BindData()
End Sub
'Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)
' If Not Page.IsPostBack Then
' BindData()
' End If
'End Sub
Sub BindData()
Dim strConn As String = "server=pharos;uid=XXX;pwd=XXX;database=DotNetNuke"
Dim sql As String = "Select EventID, EventName, EventDateBegin, EventTimeBegin, HomeAway, VarsityJV, OppWins, OppLosses, WinLossTie from dbo.AVCalendar_V where ModuleId='" & _
_calModuleId & "' and " & _
"(EventDateEnd > '" & Date.Now.Date & "' or EventDateEnd is null) order by EventDateBegin ASC"
Dim conn As New SqlConnection(strConn)
Dim objDR As SqlDataReader
Dim Cmd As New SqlCommand(sql, conn)
conn.Open()
objDR = Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
MyDataGrid.DataSource = objDR
MyDataGrid.DataBind()
conn.Close()
End Sub
End Class
While the aspx is rather straight forward:
VB.NET:
<asp:Datagrid runat="server" Id="MyDataGrid" GridLines="Both" cellpadding="2" cellspacing="0"
Headerstyle-BackColor="#ff8401" Headerstyle-Font-Name="Arial" Headerstyle-Font-Size="8" Headerstyle-Font-Bold="True"
BackColor="#b9bfdc" Font-Name="Arial" Font-Size="8" BorderColor="Black" AutogenerateColumns="False"
OnEditcommand="MyDataGrid_EditCommand" OnCancelcommand="MyDataGrid_Cancel" OnUpdateCommand="MyDataGrid_UpdateCommand" OnItemCreated="Item_Created">
<Columns>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Update" CancelText="Cancel" EditText="<img src=/Images/Edit.gif Border=0 Width=12 Height=12>"
ItemStyle-HorizontalAlign="Center" HeaderText="Edit"></asp:EditCommandColumn>
<asp:BoundColumn DataField="EventID" HeaderText="ID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn DataField="EventName" HeaderText="EventName"></asp:BoundColumn>
<asp:BoundColumn DataField="EventDateBegin" HeaderText="Date"></asp:BoundColumn>
<asp:BoundColumn DataField="EventTimeBegin" HeaderText="Time"></asp:BoundColumn>
... etc
How in the heck (and of course I am as ametuer as they come) do I employ the use of a dropdown instead of a textbox for certain fields while also providing the dropdown options?
Thanks