在我的 Web 应用程序项目中重用网站项目中的代码
这是代码。我现在还在代码隐藏中遇到错误,变量已经存在并且方法具有相同的签名,但我无法在代码隐藏的任何地方找到这些重复项。
.ASPX
<%@ Page Title="Mijn oefeningen" Language="VB" MasterPageFile="~/main.master" AutoEventWireup="false" Inherits="Fitness2.exercises" Codebehind="exercises.aspx.vb" %>
<%@ MasterType VirtualPath="~/main.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHBigBanner" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="CPHQuickSearch" Runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CPHCenter" Runat="Server">
<asp:Label ID="lblStatus" runat="server" />
<div class="section">
<div class="action">
<asp:Button ID="btnAddNew" runat="server" Text="Nieuwe oefening aanmaken" />
</div>
</div>
<div class="section">
<asp:GridView DataKeyNames="id" Width="100%" ID="gvExercises" runat="server" GridLines="Horizontal" CellPadding="10" AllowSorting="true" AllowPaging="True" PageSize="50" AutoGenerateColumns="False" >
<PagerSettings Mode="NumericFirstLast" Position="Bottom" />
<PagerStyle CssClass="gridpager" HorizontalAlign="Center" />
<RowStyle CssClass="gv_even" Height="20" />
<AlternatingRowStyle CssClass="gv_odd" />
<HeaderStyle CssClass="gv_header" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Bekijk"/>
<asp:TemplateField>
<ItemTemplate>
<asp:linkButton runat="server" CausesValidation="false" ID="Edit" Text="Bewerk" CommandName="EditItem" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="title" HeaderText="Oefening naam">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="category" HeaderText="Categorie">
<ItemTemplate>
<asp:Label ID="category" runat="server" Text='<%# Eval("category") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="/images/delete.png" CausesValidation="false" ID="Delete" OnClientClick="javascript:return confirm('Weet je zeker dat je dit item wilt verwijderen?');" ToolTip="Verwijder" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsExercises" runat="server" SortParameterName="sortExpression" SelectMethod="GetExercisesPagedSorted" InsertMethod="InsertExercise" DeleteMethod="DeleteExerciseById" SelectCountMethod="GetExercisesCount" TypeName="ExerciseBLL" EnablePaging="true">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
<asp:DetailsView GridLines="None" AutoGenerateRows="False" DataKeyNames="id" DataSourceID="odsdvExercises" ID="dvExercises" Width="100%" runat="server">
<Fields>
<asp:CommandField ButtonType="Link" ValidationGroup="Exercises" ControlStyle-CssClass="link" EditText="Item bewerken" NewText="Nieuw item aanmaken" UpdateText="Opslaan" InsertText="Opslaan" ShowEditButton="True" CancelText="Annuleren" ShowInsertButton="true" />
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("id")%>
</ItemTemplate>
<EditItemTemplate>
<%#Eval("id")%>
</EditItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Oefening naam *" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text='<%# Bind("title") %>'/>
<asp:RequiredFieldValidator ID="ReqdfguiredF43ieldValidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text=""/>
<asp:RequiredFieldValidator ID="Requdf1giredF43ieldVagfglidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Doelstelling">
<ItemTemplate>
<asp:Literal ID="Lafgdfdbel1c" runat="server" Text='<%# Eval("goal").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("goal") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tempo">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("tempo").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("tempo") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("description").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" CssClass="textbox" runat="server" Text='<%# Bind("description") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Aantal sets">
<ItemTemplate>
<asp:Literal ID="La1fgdfdbel1c" runat="server" Text='<%# Eval("sets").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("sets") %>'/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdbel1c" runat="server" Text='<%# Eval("reprange_min").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_min") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maxmimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdb6el1c" runat="server" Text='<%# Eval("reprange_max").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_max") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularExspressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularsExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minuten">
<ItemTemplate>
<asp:Literal ID="La11f3gdfdb6el1c" runat="server" Text='<%# Eval("minutes").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("minutes") %>'/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="YouTube link">
<ItemTemplate>
<asp:Literal ID="La11f3gdfd2b6el1c" runat="server" Text='<%# Fitness2.GlobalFunctions.GetVideoEmbed(Eval("youtube").tostring) %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="youtube" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("youtube") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="youtube" MaxLength="2" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categorie" HeaderStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label ID="Label1b" runat="server" Text='<%# Bind("category") %>'/>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" SelectedValue='<%# Bind("category") %>' DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsdvExercises" TypeName="ExerciseBLL" SelectMethod="GetExerciseById" InsertMethod="InsertExercise" UpdateMethod="UpdateExercise" runat="server">
<SelectParameters>
<asp:ControlParameter ControlID="gvExercises" Name="id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:SqlDataSource ID="sqldsCategories" ConnectionString="<%$ConnectionStrings:conn1 %>" runat="server"></asp:SqlDataSource>
</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="CPHRight" Runat="Server">
</asp:Content>
.ASPX.VB
Imports Fitness2.GlobalFunctions
Imports System.Drawing
Imports System.IO
Partial Class exercises
Inherits System.Web.UI.Page
Private _userid As String
这里出现错误:“_userid”已在此类中声明为“Private _userid As String”。
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
< strong>这里我收到错误:“Protected Sub Page_Load(sender As Object, e As System.EventArgs)”具有多个具有相同签名的定义。
_userid = GetFieldFromSession(Session, "//root/user/userid")
If Not Page.IsPostBack Then
BindExercises()
End If
End Sub
'**************** TASKS ****************
Protected Sub BindExercises()
odsExercises.SelectParameters.Clear()
gvExercises.DataSourceID = "odsExercises"
odsExercises.SelectParameters.Add("maximumRows", gvExercises.PageSize)
odsExercises.SelectParameters.Add("startRowIndex", gvExercises.PageIndex)
odsExercises.SelectParameters.Add("sortExpression", odsExercises.SortParameterName)
odsExercises.SelectParameters.Add("userid", _userid)
'gvExercises.DataBind()
End Sub
Protected Sub lbtnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If
End Sub
Protected Sub dvExercises_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvExercises.ItemInserting
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If
e.Cancel = True
End Sub
Protected Sub odsdvExercises_Inserted(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Inserted
gvExercises.DataBind()
End Sub
Protected Sub odsdvExercises_Updated(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Updated
gvExercises.DataBind()
End Sub
Protected Sub dvExercises_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvExercises.ItemUpdating
Dim ID As Integer = CInt(dvExercises.DataKey.Value)
'retrieve controls
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As Integer = CType(dvExercises.FindControl("ddlcategory"), DropDownList).SelectedIndex
If categorydropdown <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim dt As fitness.exercisesDataTable = TA.GetExerciseById(ID)
Dim returnval As Integer = TA.Update(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, dt(0).locpath.ToString, False, DateTime.Now, ID)
Select Case returnval
Case 0
lblStatus.Text = GetStatus("Whoops", True)
Case 1
gvExercises.DataBind()
lblStatus.Text = GetStatus("Item opgeslagen", False)
End Select
e.Cancel = True
End Sub
Protected Sub gvExercises_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvExercises.RowDataBound
Dim gvr As GridViewRow = e.Row
If gvr.RowType = DataControlRowType.DataRow Then
Dim imgBtn As ImageButton
imgBtn = CType(e.Row.FindControl("Delete"), ImageButton)
imgBtn.CommandArgument = gvr.RowIndex.ToString
Dim lnkBtn As LinkButton
lnkBtn = CType(e.Row.FindControl("Edit"), LinkButton)
lnkBtn.CommandArgument = gvr.RowIndex.ToString
End If
End Sub
Protected Sub gvExercises_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvExercises.RowCommand
If e.CommandName = "DeleteEvent" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
odsExercises.DeleteParameters.Clear()
odsExercises.DeleteParameters.Add("id", objectId)
odsExercises.Delete()
End If
If e.CommandName = "EditItem" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
'floran
ViewState("id") = objectId.ToString
BindDetailsView()
'gvExercises.SelectedValue
'dvExercises.ChangeMode(DetailsViewMode.Edit)
End If
End Sub
Protected Sub dvExercises_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs) Handles dvExercises.ItemCommand
End Sub
Protected Sub BindDetailsView()
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
dvExercises.DataSourceID = ""
dvExercises.DataSource = TA.GetExerciseById(ViewState("id")) ' customer.FetchByCustomerType(ViewState("CustomerType").ToString())
dvExercises.DataBind()
dvExercises.ChangeMode(DetailsViewMode.Edit)
End Sub
Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
dvExercises.ChangeMode(DetailsViewMode.Insert)
End Sub
Protected Sub gvExercises_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvExercises.SelectedIndexChanged
If gvExercises.SelectedDataKey IsNot Nothing Then
Session("exerciseId") = CInt(gvExercises.SelectedDataKey.Value)
'ReportError("Session(exerciseId)", Session("exerciseId").ToString)
End If
End Sub
End Class
Here's the code. I now also get errors in codebehind that a variable already exists and method has identical signature, but I cant find those duplicates anywhere in the code behind.
.ASPX
<%@ Page Title="Mijn oefeningen" Language="VB" MasterPageFile="~/main.master" AutoEventWireup="false" Inherits="Fitness2.exercises" Codebehind="exercises.aspx.vb" %>
<%@ MasterType VirtualPath="~/main.master" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="CPHBigBanner" Runat="Server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="CPHQuickSearch" Runat="Server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="CPHCenter" Runat="Server">
<asp:Label ID="lblStatus" runat="server" />
<div class="section">
<div class="action">
<asp:Button ID="btnAddNew" runat="server" Text="Nieuwe oefening aanmaken" />
</div>
</div>
<div class="section">
<asp:GridView DataKeyNames="id" Width="100%" ID="gvExercises" runat="server" GridLines="Horizontal" CellPadding="10" AllowSorting="true" AllowPaging="True" PageSize="50" AutoGenerateColumns="False" >
<PagerSettings Mode="NumericFirstLast" Position="Bottom" />
<PagerStyle CssClass="gridpager" HorizontalAlign="Center" />
<RowStyle CssClass="gv_even" Height="20" />
<AlternatingRowStyle CssClass="gv_odd" />
<HeaderStyle CssClass="gv_header" />
<Columns>
<asp:CommandField ShowSelectButton="True" SelectText="Bekijk"/>
<asp:TemplateField>
<ItemTemplate>
<asp:linkButton runat="server" CausesValidation="false" ID="Edit" Text="Bewerk" CommandName="EditItem" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="title" HeaderText="Oefening naam">
<ItemTemplate>
<asp:Label ID="lblTitle" runat="server" Text='<%# Eval("title") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField SortExpression="category" HeaderText="Categorie">
<ItemTemplate>
<asp:Label ID="category" runat="server" Text='<%# Eval("category") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton runat="server" ImageUrl="/images/delete.png" CausesValidation="false" ID="Delete" OnClientClick="javascript:return confirm('Weet je zeker dat je dit item wilt verwijderen?');" ToolTip="Verwijder" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:ObjectDataSource ID="odsExercises" runat="server" SortParameterName="sortExpression" SelectMethod="GetExercisesPagedSorted" InsertMethod="InsertExercise" DeleteMethod="DeleteExerciseById" SelectCountMethod="GetExercisesCount" TypeName="ExerciseBLL" EnablePaging="true">
<DeleteParameters>
<asp:Parameter Name="Id" Type="Int32" />
</DeleteParameters>
</asp:ObjectDataSource>
<asp:DetailsView GridLines="None" AutoGenerateRows="False" DataKeyNames="id" DataSourceID="odsdvExercises" ID="dvExercises" Width="100%" runat="server">
<Fields>
<asp:CommandField ButtonType="Link" ValidationGroup="Exercises" ControlStyle-CssClass="link" EditText="Item bewerken" NewText="Nieuw item aanmaken" UpdateText="Opslaan" InsertText="Opslaan" ShowEditButton="True" CancelText="Annuleren" ShowInsertButton="true" />
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<%#Eval("id")%>
</ItemTemplate>
<EditItemTemplate>
<%#Eval("id")%>
</EditItemTemplate>
<InsertItemTemplate>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Oefening naam *" HeaderStyle-Font-Bold="true">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("title") %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text='<%# Bind("title") %>'/>
<asp:RequiredFieldValidator ID="ReqdfguiredF43ieldValidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="title" Width="400" MaxLength="150" CssClass="textbox" runat="server" Text=""/>
<asp:RequiredFieldValidator ID="Requdf1giredF43ieldVagfglidator1" ValidationGroup="Exercises" ControlToValidate="title" runat="server" ErrorMessage="*" Display="Dynamic"/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Doelstelling">
<ItemTemplate>
<asp:Literal ID="Lafgdfdbel1c" runat="server" Text='<%# Eval("goal").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("goal") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="goal" MaxLength="150" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tempo">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("tempo").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("tempo") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="tempo" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Omschrijving">
<ItemTemplate>
<asp:Literal ID="Lafdgdfdbel1c" runat="server" Text='<%# Eval("description").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" CssClass="textbox" runat="server" Text='<%# Bind("description") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="description" TextMode="MultiLine" Rows="3" Columns="50" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Aantal sets">
<ItemTemplate>
<asp:Literal ID="La1fgdfdbel1c" runat="server" Text='<%# Eval("sets").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("sets") %>'/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="sets" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="sets" ValidationGroup="Exercises" ID="RegularExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdbel1c" runat="server" Text='<%# Eval("reprange_min").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_min") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_min" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_min" ValidationGroup="Exercises" ID="RegularExpresfsionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Maxmimum herhalingen">
<ItemTemplate>
<asp:Literal ID="La1f3gdfdb6el1c" runat="server" Text='<%# Eval("reprange_max").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("reprange_max") %>'/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularExspressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="reprange_max" MaxLength="2" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="reprange_max" ValidationGroup="Exercises" ID="RegularsExpressionValidator7" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Minuten">
<ItemTemplate>
<asp:Literal ID="La11f3gdfdb6el1c" runat="server" Text='<%# Eval("minutes").tostring %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text='<%# Bind("minutes") %>'/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="minutes" MaxLength="3" Width="50" CssClass="textbox" runat="server" Text=""/>
<asp:RegularExpressionValidator ControlToValidate="minutes" ValidationGroup="Exercises" ID="RegularExpressionValidator8" runat="server" ValidationExpression="[0-9]+" ErrorMessage="Ongeldig getal" />
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="YouTube link">
<ItemTemplate>
<asp:Literal ID="La11f3gdfd2b6el1c" runat="server" Text='<%# Fitness2.GlobalFunctions.GetVideoEmbed(Eval("youtube").tostring) %>'/>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="youtube" MaxLength="50" Width="400" CssClass="textbox" runat="server" Text='<%# Bind("youtube") %>'/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:TextBox ID="youtube" MaxLength="2" Width="400" CssClass="textbox" runat="server" Text=""/>
</InsertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Categorie" HeaderStyle-VerticalAlign="Top">
<ItemTemplate>
<asp:Label ID="Label1b" runat="server" Text='<%# Bind("category") %>'/>
</ItemTemplate>
<EditItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" SelectedValue='<%# Bind("category") %>' DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</EditItemTemplate>
<InsertItemTemplate>
<table>
<tr>
<td>Selecteer bestaande categorie:</td>
<td>
<asp:DropDownList ID="ddlcategory" DataSourceID="sqldsCategories" DataTextField="title" DataValueField="title" runat="server">
</asp:DropDownList>
</td>
</tr>
<tr>
<td>of maak een nieuwe categorie aan:</td>
<td>
<asp:TextBox ID="category" Width="200" MaxLength="50" CssClass="textbox" runat="server" />
<asp:RequiredFieldValidator ID="RequirebbdF43ieldValidator1" ValidationGroup="tasks" ControlToValidate="category" runat="server" ErrorMessage="*" Display="Dynamic"/>
</td>
</tr>
</table>
</InsertItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="odsdvExercises" TypeName="ExerciseBLL" SelectMethod="GetExerciseById" InsertMethod="InsertExercise" UpdateMethod="UpdateExercise" runat="server">
<SelectParameters>
<asp:ControlParameter ControlID="gvExercises" Name="id" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<asp:SqlDataSource ID="sqldsCategories" ConnectionString="<%$ConnectionStrings:conn1 %>" runat="server"></asp:SqlDataSource>
</div>
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="CPHRight" Runat="Server">
</asp:Content>
.ASPX.VB
Imports Fitness2.GlobalFunctions
Imports System.Drawing
Imports System.IO
Partial Class exercises
Inherits System.Web.UI.Page
Private _userid As String
here I get error: '_userid' is already declared as 'Private _userid As String' in this class.
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
Here I get error: 'Protected Sub Page_Load(sender As Object, e As System.EventArgs)' has multiple definitions with identical signatures.
_userid = GetFieldFromSession(Session, "//root/user/userid")
If Not Page.IsPostBack Then
BindExercises()
End If
End Sub
'**************** TASKS ****************
Protected Sub BindExercises()
odsExercises.SelectParameters.Clear()
gvExercises.DataSourceID = "odsExercises"
odsExercises.SelectParameters.Add("maximumRows", gvExercises.PageSize)
odsExercises.SelectParameters.Add("startRowIndex", gvExercises.PageIndex)
odsExercises.SelectParameters.Add("sortExpression", odsExercises.SortParameterName)
odsExercises.SelectParameters.Add("userid", _userid)
'gvExercises.DataBind()
End Sub
Protected Sub lbtnInsert_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If
End Sub
Protected Sub dvExercises_ItemInserting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewInsertEventArgs) Handles dvExercises.ItemInserting
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As DropDownList = CType(dvExercises.FindControl("ddlcategory"), DropDownList)
If category = "" Then 'user wants to create new category
If categorydropdown.Items.Count = 0 Then
lblStatus.Text = GetStatus("Maak aub eerst een categorie aan", True)
Else
If categorydropdown.SelectedIndex <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
End If
End If
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim returnval As Integer
TA.InsertExercise(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, "", False, 0, returnval)
If returnval > 0 Then
Session("exerciseId") = returnval
gvExercises.DataBind()
lblStatus.Text = GetStatus("Oefening toegevoegd", False)
Else
lblStatus.Text = GetStatus("Whoops", True)
End If
e.Cancel = True
End Sub
Protected Sub odsdvExercises_Inserted(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Inserted
gvExercises.DataBind()
End Sub
Protected Sub odsdvExercises_Updated(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs) Handles odsdvExercises.Updated
gvExercises.DataBind()
End Sub
Protected Sub dvExercises_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewUpdateEventArgs) Handles dvExercises.ItemUpdating
Dim ID As Integer = CInt(dvExercises.DataKey.Value)
'retrieve controls
Dim Title As String = Trim(CType(dvExercises.FindControl("title"), TextBox).Text)
Dim userid As String = _userid
Dim goal As String = Trim(CType(dvExercises.FindControl("goal"), TextBox).Text)
Dim tempo As String = Trim(CType(dvExercises.FindControl("tempo"), TextBox).Text)
Dim description As String = Trim(CType(dvExercises.FindControl("description"), TextBox).Text)
If description.Length > 4000 Then description = description.Substring(0, 4000)
Dim sets As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("sets"), TextBox).Text), sets)
Dim reprange_min As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_min"), TextBox).Text), reprange_min)
Dim reprange_max As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("reprange_max"), TextBox).Text), reprange_max)
Dim minutes As Integer
Int32.TryParse(Trim(CType(dvExercises.FindControl("minutes"), TextBox).Text), minutes)
Dim youtube As String = Trim(CType(dvExercises.FindControl("youtube"), TextBox).Text)
'Dim ispublic As Boolean = CType(dvExercises.FindControl("ispublic"), CheckBox).Checked
Dim category As String = Trim(CType(dvExercises.FindControl("category"), TextBox).Text)
Dim categorydropdown As Integer = CType(dvExercises.FindControl("ddlcategory"), DropDownList).SelectedIndex
If categorydropdown <> -1 Then category = CType(dvExercises.FindControl("ddlcategory"), DropDownList).Text
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
Dim dt As fitness.exercisesDataTable = TA.GetExerciseById(ID)
Dim returnval As Integer = TA.Update(New Guid(userid), Title, category, goal, tempo, description, sets, reprange_min, reprange_max, minutes, youtube, dt(0).locpath.ToString, False, DateTime.Now, ID)
Select Case returnval
Case 0
lblStatus.Text = GetStatus("Whoops", True)
Case 1
gvExercises.DataBind()
lblStatus.Text = GetStatus("Item opgeslagen", False)
End Select
e.Cancel = True
End Sub
Protected Sub gvExercises_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvExercises.RowDataBound
Dim gvr As GridViewRow = e.Row
If gvr.RowType = DataControlRowType.DataRow Then
Dim imgBtn As ImageButton
imgBtn = CType(e.Row.FindControl("Delete"), ImageButton)
imgBtn.CommandArgument = gvr.RowIndex.ToString
Dim lnkBtn As LinkButton
lnkBtn = CType(e.Row.FindControl("Edit"), LinkButton)
lnkBtn.CommandArgument = gvr.RowIndex.ToString
End If
End Sub
Protected Sub gvExercises_OnRowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs) Handles gvExercises.RowCommand
If e.CommandName = "DeleteEvent" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
odsExercises.DeleteParameters.Clear()
odsExercises.DeleteParameters.Add("id", objectId)
odsExercises.Delete()
End If
If e.CommandName = "EditItem" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim data As DataKey = gvExercises.DataKeys(index)
Dim objectId As Integer = data.Values("id")
'floran
ViewState("id") = objectId.ToString
BindDetailsView()
'gvExercises.SelectedValue
'dvExercises.ChangeMode(DetailsViewMode.Edit)
End If
End Sub
Protected Sub dvExercises_ItemCommand(ByVal sender As Object, ByVal e As DetailsViewCommandEventArgs) Handles dvExercises.ItemCommand
End Sub
Protected Sub BindDetailsView()
Dim TA As New fitnessTableAdapters.exercisesTableAdapter
dvExercises.DataSourceID = ""
dvExercises.DataSource = TA.GetExerciseById(ViewState("id")) ' customer.FetchByCustomerType(ViewState("CustomerType").ToString())
dvExercises.DataBind()
dvExercises.ChangeMode(DetailsViewMode.Edit)
End Sub
Protected Sub btnAddNew_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnAddNew.Click
dvExercises.ChangeMode(DetailsViewMode.Insert)
End Sub
Protected Sub gvExercises_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles gvExercises.SelectedIndexChanged
If gvExercises.SelectedDataKey IsNot Nothing Then
Session("exerciseId") = CInt(gvExercises.SelectedDataKey.Value)
'ReportError("Session(exerciseId)", Session("exerciseId").ToString)
End If
End Sub
End Class
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不会保留这两种解决方案,而是将网站项目转换为 WAP。
您需要将网站项目中 app_code 文件夹中的所有内容移动到单独的类库中,或者直接将它们包含在 WAP 中(可能没有 app_code 文件夹,因为这具有特殊意义),在这种情况下,它们将是编译到主 WAP 程序集中。
您可能必须使用命名空间等才能使其正常工作,但影响应该很小。主要区别(和好处)是代码是在编译时构建的,并且您的源代码(*.cs)不会部署到服务器。
另请注意,在 VS 中,有一个上下文菜单选项可将网站项目实体转换为 Web 应用程序实体。这将创建 WAP 所需的 .designer.cs 文件,并在解决方案资源管理器中组织文件 - .aspx、.cs 和 .designer.cs 文件将显示为可扩展节点。
这是 MSDN 上一篇精彩的文章,介绍了转换过程< /a>.
WAP 运行后,添加服务就像
右键单击 - 添加新项目...
一样简单Rather than keeping both solutions, I'd convert the website project to a WAP.
You'll need to move everything in your app_code folder in the website project either into a separate class library or just include them in the WAP directly (probably without the app_code folder, as that has special significance), in which case they'll be compiled into the primary WAP assembly.
You may have to play with namespaces, etc. in order to get this to work correctly, but the impact should be minimal. The major difference (and benefit) is that the code is built at compile time, and your source (*.cs) is not deployed to the server.
Also note that, in VS, there's a context menu option to convert website project entities into web application entities. This will create the .designer.cs files needed by the WAP as well as organize the files in the solution explorer - the .aspx, .cs and .designer.cs files will appear as an expandable node.
Here's an excellent article on MSDN covering the conversion process.
Once you've got the WAP running, adding services is as simple as
right click - add new item...