select and update multiple checkbox in gridview - html

I want to select multible record in one time and update them by a buttom
I searched the internet by it's always cs and I want vb.net
I did my grid view as following
<asp:GridView ID="GridView1" runat="server" AutoGenerateCheckboxColumn="True"
CheckboxColumnIndex="0" AllowSorting="true"
AutoGenerateColumns="False" DataKeyNames="USER_ID"
DataSourceID="SqlDataSource1StudentActivList" CellPadding="2">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="FirstName" HeaderText="FirstName"
SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName"
SortExpression="LastName" />
<asp:BoundField DataField="MiddleName" HeaderText="MiddleName"
SortExpression="MiddleName" />
<asp:BoundField DataField="ProgramCODE" HeaderText="ProgramCODE"
SortExpression="ProgramCODE" />
<asp:BoundField DataField="USER_NAME" HeaderText="USER_NAME"
SortExpression="USER_NAME" />
<asp:BoundField DataField="USER_Email" HeaderText="USER_Email"
SortExpression="USER_Email" />
<asp:BoundField DataField="MajorNameInEnglish" HeaderText="MajorNameInEnglish"
SortExpression="MajorNameInEnglish" />
<asp:BoundField DataField="GivenStudentID" HeaderText="GivenStudentID"
SortExpression="GivenStudentID" />
<asp:BoundField DataField="accepted" HeaderText="accepted"
SortExpression="accepted" />
<asp:BoundField DataField="Gender" HeaderText="Gender"
SortExpression="Gender" />
<asp:BoundField DataField="USER_ID" HeaderText="USER_ID" ReadOnly="True"
SortExpression="USER_ID" />
</Columns>
<SelectedRowStyle BackColor="DarkSlateBlue" ForeColor="GhostWhite" />
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1StudentActivList" runat="server"
ConnectionString="<%$ ConnectionStrings:mydbConnectionString %>"
SelectCommand="SELECT DISTINCT [FirstName], [LastName], [MiddleName], [ProgramCODE], [USER_NAME], [USER_Email], [MajorNameInEnglish], [GivenStudentID], [accepted], [Gender], [USER_ID] FROM [DIP_StudentsActivationList]">
</asp:SqlDataSource>
<p><asp:Label ID="lblSelection" runat="server" /></p>
<asp:Button ID="btupdate" runat="server" Text="Update" />
this is the VB code(converted) it's not what i want but i think i can deal with it
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Public Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(sender As Object, e As EventArgs)
If MultiSelectGridView1.SelectedDataKeys.Count > 0 Then
lblSelection.Text = "You selected employees: "
For Each k As DataKey In MultiSelectGridView1.SelectedDataKeys
lblSelection.Text += k.Value.ToString() & ", "
Next
lblSelection.Text = lblSelection.Text.TrimEnd(","C, " "C)
Else
lblSelection.Text = "No employees selected"
End If
End Sub
End Class
and I want to change the accepted status in my database by clicking the buttom
any help please

Related

Procedure or function has too many arguments specified when Gridview Editing

When I click to edit the txtHours box, I get this error when I click the submit button:
Procedure or function UpdateWish has too many arguments specified.
I'm fairly new to all this so I've probably made a simple error somewhere. It's code which was written for me and I have changed it for a different application. Should all work if I can sort this error. I use ASP.NET, VB.Net and SQL Server. There is no code in the VB file which should affect this so I haven't included that. Any help appreciated.
FRONT END
<asp:TextBox ID="txtWishText" runat="server" style="padding-left:20px; padding-right:20px; text-align:center;" Columns="5" MaxLength="5" Font-Size="Large" Height="28px" AutoComplete="off"></asp:TextBox>
<br>
<asp:ImageButton ID="btnSubmitWish" runat="server" class="BackNextButton" style="margin-top:7px;" ImageUrl="~/files/images/icons/submitButton.gif" ValidationGroup="Wish" />
<br />
<asp:RequiredFieldValidator ID="rqdWish" runat="server"
ErrorMessage="Enter Hours Worked" ValidationGroup="Wish"
CssClass="error" ControlToValidate="txtWishText" Display="Dynamic"></asp:RequiredFieldValidator>
<br />
<h2 style="font-size:16px; color:#333333; font-family: 'Seymour One', sans-serif; text-align:center;">My Hours: <asp:Label ID="LabelTotalHours" runat="server" ></asp:Label></h2>
<asp:SqlDataSource ID="DSMyWishes" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
DeleteCommand="RemoveWish" DeleteCommandType="StoredProcedure"
SelectCommand="SelectFullWishesByAccount"
SelectCommandType="StoredProcedure"
UpdateCommand="UpdateWish" UpdateCommandType="StoredProcedure">
<DeleteParameters>
<asp:Parameter Name="wishID" Type="Int32" />
</DeleteParameters>
<SelectParameters>
<asp:Parameter Name="name" DbType="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="wishID" Type="Int32" />
<asp:Parameter Name="dailyHours" Type="Decimal" />
</UpdateParameters>
</asp:SqlDataSource>
<asp:GridView ID="gdvMyWishes" runat="server" CssClass="mGrid" DataSourceID="DSMyWishes" width="100%" AutoGenerateColumns="False" DataKeyNames="wishID">
<AlternatingRowStyle CssClass="alt" />
<Columns>
<asp:TemplateField HeaderText="Date" SortExpression="wishText">
<ItemTemplate>
<asp:Label ID="LabelDate" font-size="1.0em" runat="server" Text='<%# Bind("dateInserted") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Hours" SortExpression="wishText">
<EditItemTemplate>
<asp:TextBox ID="txtHours" runat="server" Columns="40" MaxLength="40" Text='<%# Bind("dailyHours") %>'></asp:TextBox>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="Label1" font-size="1.0em" runat="server" Text='<%# Bind("dailyHours") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Link"
DeleteImageUrl="~/files/images/icons/deleteIcon.png" EditImageUrl="~/files/Images/icons/editIcon.png" UpdateImageUrl="~/files/Images/icons/submitIcon.png" CancelImageUrl="~/files/Images/icons/backIcon.png"/>
</Columns>
<EmptyDataTemplate>
No hours recorded
</EmptyDataTemplate>
</asp:GridView>
SQL Server stored procedure:
ALTER PROCEDURE [UpdateWish]
#wishID int,
#dailyHours decimal(10,2)
AS
BEGIN
SET NOCOUNT ON;
UPDATE tblWishes
SET dailyHours = #dailyHours
WHERE wishID = #wishID
END
As per your code, it looks perfect for passing 2 update parameter and in stored procedure also there is 2 parameters.
Also for select and delete working fine with CommandType.StoredProcedure?
Otherwise, you should first try without stored procedure as per the following way.
Removing UpdateCommandType="StoredProcedure" and set update query in UpdateCommand
Code:
<asp:SqlDataSource ID="DSMyWishes" runat="server"
ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
DeleteCommand="RemoveWish" DeleteCommandType="StoredProcedure"
SelectCommand="SelectFullWishesByAccount"
SelectCommandType="StoredProcedure"
UpdateCommand="UPDATE tblWishes SET dailyHours = #dailyHours WHERE wishID = #wishID">

Images aren't showing in gridtable

I can't see the image files I included in my asp.net page. The images are put into the linked access database table first, and I also included the images into the same folder as my web application.
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" AutoGenerateSelectButton="True" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" CellPadding="5" Font-Names="Arial">
<Columns>
<asp:BoundField DataField="ProductID" HeaderText="Product ID" />
<asp:BoundField DataField="ProductName" HeaderText="Product Name" />
<asp:BoundField DataField="ProductPrice" HeaderText="Product Price" />
<asp:BoundField DataField="QtyInStock" HeaderText="Quantity in stock" />
<asp:ImageField DataImageUrlField="ProductImage" HeaderText="Image">
<ControlStyle BorderStyle="Groove" Height="260px" Width="300px" />
</asp:ImageField>
</Columns>
<EmptyDataRowStyle BackColor="White" />
<FooterStyle BackColor="White" />
<HeaderStyle BackColor="White" />
<PagerStyle BackColor="White" />
<RowStyle BackColor="White" />
</asp:GridView>
The product image field is where the images should be.

Make bound field in grid like HyperLinkField

I have a nested gridview as shown below. I populate the gridview from a stored procedure and method in my DAL/BLL layers. This works fine and data is returned to my nested gridview as I expect.
What I'd like to do though, is have the boundfield (VisitTypeId) in my nested gridview as a hyperlink, so the user can click on it and be redirected to the related 'Visit' for the Patient (in other words, 'where ID={0} and VisitTypeId={0}').
I'm certain this must be possible, but can't find a way to do it. Can someone please help?
Markup:
<asp:GridView ID="gvPatients" runat="server" AutoGenerateColumns="False" DataSourceID="odsPatients" OnRowDataBound="gvVisits_RowDataBound"
DataKeyNames="ID" AllowPaging="True" CssClass="interactTable" CellPadding="4"
AllowSorting="True" meta:resourcekey="gvPersonsResource1">
<HeaderStyle CssClass="header" />
<RowStyle CssClass="row"/>
<Columns>
<asp:TemplateField Visible="False">
<ItemTemplate>
<asp:Label ID="lblID" runat="server" Text='<%# Eval("ID")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:Boundfield DataField="ID" HeaderText="ID" />
<asp:Boundfield DataField="Forename" HeaderText="Forename" />
<asp:Boundfield DataField="Surname" HeaderText="Surname" />
<asp:Boundfield DataField="DoB" HeaderText="DoB" DataFormatString="{0:dd/MM/yyyy}" />
<asp:TemplateField HeaderText="Visits">
<ItemTemplate>
<asp:GridView ID="gvVisits" runat="server" AutoGenerateColumns="false" BorderWidth="0" ShowHeader="false" >
<Columns>
<%-- <asp:BoundField DataField="PatientID" Visible="false" /> --%>
<asp:BoundField DataField="VisitTypeID" />
</Columns>
</asp:GridView>
</ItemTemplate>
</asp:TemplateField>
<asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="~/AddEditPatient.aspx?ID={0}" HeaderText="Edit" Text="Edit" />
</Columns>
</asp:GridView>
DAL:
Public Shared Function GetVisitType(PatientId As Integer) As DataSet
Using myConnection As New SqlConnection(AppConfiguration.ConnectionString)
Using myCommand As New SqlCommand("SPGetVisitType", myConnection)
myCommand.CommandType = CommandType.StoredProcedure
myCommand.Parameters.AddWithValue("PatientID", PatientId)
myConnection.Open()
Dim ds As New DataSet()
Using myAdapter As New SqlDataAdapter(myCommand)
myAdapter.Fill(ds)
Return ds
End Using
myConnection.Close()
End Using
End Using
End Function
BLL:
Public Shared Function GetVisitType(ByVal PatientId As Integer) As DataSet
Dim ds As DataSet = ScreeningTestDAL.Visit.GetVisitType(PatientId)
Return ds
End Function
Codebehind:
Protected Sub gvVisits_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
Dim gv As GridView = DirectCast(e.Row.FindControl("gvVisits"), GridView)
Dim PatientId As Integer = Convert.ToInt32(e.Row.Cells(1).Text)
Dim ds1 As DataSet = ScreeningTestBLL.VisitManager.GetVisitType(PatientId)
gv.DataSource = ds1
gv.DataBind()
End If
End Sub

My gridview doesn't show in Browser due to parameter value

I am using ASP.net and at some point I have a gridview that doesn't show up in my browser when I debug my project. On that same page do I use a textbox and that one does show up.
This is the HTML.
<%# Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/MasterPages/SvShop.Master" CodeBehind="Mijnoverzicht.aspx.vb" Inherits="SvShop.Mijnoverzicht" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<h1>Mijn Artikelen</h1>
<table>
<tr>
<td>Email</td>
<td>
<asp:TextBox ID="txtMijnEmail" runat="server" CssClass="tekstvak" Width="190px"></asp:TextBox>
</td>
</tr>
</table>
<div class="OverzichtMijn">
<asp:GridView ID="GridViewMijn" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataSourceID="MijnDataSource" AllowSorting="True" Width="845px">
<Columns>
<asp:BoundField DataField="ArtikelBeschrijving" HeaderText="Beschrijving" SortExpression="ArtikelBeschrijving" />
<asp:BoundField DataField="ArtikelPrijs" HeaderText="Prijs" SortExpression="ArtikelPrijs" />
<asp:BoundField DataField="ArtikelAankoopdatum" HeaderText="Aankoopdatum" SortExpression="ArtikelAankoopdatum" />
<asp:BoundField DataField="ArtikelTekoopgezet" HeaderText="Tekoopgezet" SortExpression="ArtikelTekoopgezet" />
<asp:BoundField DataField="GebruikersNaam" HeaderText="Naam" SortExpression="GebruikersNaam" />
<asp:BoundField DataField="GebruikersVoornaam" HeaderText="Voornaam" SortExpression="GebruikersVoornaam" />
<asp:BoundField DataField="GebruikersEmail" HeaderText="Email" SortExpression="GebruikersEmail" />
<asp:BoundField DataField="GebruikersGSM" HeaderText="GSM" SortExpression="GebruikersGSM" />
</Columns>
<EditRowStyle CssClass="GridViewEditRow" />
</asp:GridView>
<asp:SqlDataSource ID="MijnDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SvShopInternString %>" ProviderName="<%$ ConnectionStrings:SvShopInternString.ProviderName %>" SelectCommand="SELECT tblArtikel.ArtikelBeschrijving, tblArtikel.ArtikelPrijs, tblArtikel.ArtikelAankoopdatum, tblArtikel.ArtikelTekoopgezet, tblGebruiker.GebruikersNaam, tblGebruiker.GebruikersVoornaam, tblGebruiker.GebruikersEmail, tblGebruiker.GebruikersGSM FROM ((tblArtikel INNER JOIN tblGebruiker ON tblArtikel.GebruikersID = tblGebruiker.GebruikersID) INNER JOIN tblRubriek ON tblArtikel.RubriekID = tblRubriek.RubriekID) WHERE (tblGebruiker.GebruikersEmail = '#Email')"></asp:SqlDataSource>
</div>
</asp:Content>
This is the browser view.
The problem should be in this line of code.
<asp:SqlDataSource ID="MijnDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:SvShopInternString %>" ProviderName="<%$ ConnectionStrings:SvShopInternString.ProviderName %>" SelectCommand="SELECT tblArtikel.ArtikelBeschrijving, tblArtikel.ArtikelPrijs, tblArtikel.ArtikelAankoopdatum, tblArtikel.ArtikelTekoopgezet, tblGebruiker.GebruikersNaam, tblGebruiker.GebruikersVoornaam, tblGebruiker.GebruikersEmail, tblGebruiker.GebruikersGSM FROM ((tblArtikel INNER JOIN tblGebruiker ON tblArtikel.GebruikersID = tblGebruiker.GebruikersID) INNER JOIN tblRubriek ON tblArtikel.RubriekID = tblRubriek.RubriekID) WHERE (tblGebruiker.GebruikersEmail = '#Email')"></asp:SqlDataSource>
The parameter
#Email
gets his value from the textbox above with this code:
Protected Sub txtMijnEmail_TextChanged(sender As Object, e As EventArgs) Handles txtMijnEmail.TextChanged
MijnDataSource.SelectCommand.Replace("#Email", txtMijnEmail.Text)
GridViewMijn.DataBind()
End Sub
Overkill - just add a Control Parameter to the SelectParameters:
<asp:SqlDataSource ID="MijnDataSource" runat="server"
ConnectionString="<%$ ConnectionStrings:SvShopInternString %>"
ProviderName="<%$ ConnectionStrings:SvShopInternString.ProviderName %>"
SelectCommand="SELECT <snip> WHERE (tblGebruiker.GebruikersEmail = '#Email')">
<SelectParameters>
<asp:ControlParameter
ControlID="txtMijnEmail"
PropertyName="Text"
Name="Email">
</asp:ControlParameter>
</SelectParameters>
</asp:SqlDataSource>
And obviously make sure your Select command returns a dataset when a valid email is provided.
Also consider temporarily setting GridViewMijn.ShowHeader="true" and GridViewMijn.EmptyDataText="No Data returned" for debugging purposes

SQL Show most current record for each task by date

I want to show the most recently updated record for each task.
Currently I am only getting the most recent of all records no matter what task.
Here is the front end code
<asp:SqlDataSource ID="GrabAssignedTasks" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT Backlog.Story, Tasks.Task, Tasks.EstimatedHours, Tasks.UserStoryTaskID, Tasks_Log.TaskLogID, Tasks_Log.HoursLeft, Tasks_Log.ModifiedDate
FROM Backlog
INNER JOIN Tasks ON Backlog.UserStoryID = Tasks.UserStoryID
INNER JOIN Tasks_Log ON Tasks.UserStoryTaskID = Tasks_Log.TaskID
WHERE (Tasks.OwnershipID = #UserID) AND (Tasks_Log.ModifiedDate = (SELECT MAX(ModifiedDate) AS Expr1
FROM Tasks_Log AS Tasks_Log_1))">
<SelectParameters>
<asp:SessionParameter Name="UserID" SessionField="loggedInUser" />
</SelectParameters>
</asp:SqlDataSource>
</div>
<header class="jumbotron hero-spacer">
<asp:Button ID="BackToTasks" runat="server" Text="Back" OnClick="BackToTasks_Click" CssClass="btn btn-primary btn-large" />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="GrabAssignedTasks" Height="179px" Width="829px" OnSelectedIndexChanged="HoursChange_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="Story" HeaderText="Story" SortExpression="Story" />
<asp:BoundField DataField="Task" HeaderText="Task" SortExpression="Task" />
<asp:BoundField DataField="EstimatedHours" HeaderText="Estimated Hours" SortExpression="EstimatedHours" />
<asp:BoundField DataField="UserStoryTaskID" HeaderText="UserStoryTaskID" SortExpression="UserStoryTaskID" InsertVisible="False" ReadOnly="True" HeaderStyle-CssClass="hidden-field" ItemStyle-CssClass="hidden-field"/>
<asp:BoundField DataField="TaskLogID" HeaderText="TaskLogID" SortExpression="TaskLogID" InsertVisible="False" ReadOnly="True" HeaderStyle-CssClass="hidden-field" ItemStyle-CssClass="hidden-field"/>
<asp:BoundField DataField="HoursLeft" HeaderText="Hours Left" SortExpression="HoursLeft" />
<asp:BoundField DataField="ModifiedDate" HeaderText="Last Updated" SortExpression="ModifiedDate" />
<asp:CommandField ShowSelectButton="True" />
</Columns>
</asp:GridView>
</header>
I have nothing specific to this in the C# code.
Here is a picture of the table in the database I am using.
Database table
You are not joining Table Tasks_Log with Tasks_Log_1, so what happens is that only entries in Tasks_Log where the modified date matches "30/11/2015" get returned, regardless of the task. Add an entry in that WHERE clause for Tasks_Log_1 to ensure you are also matching on the correct TaskID:
SELECT Backlog.Story, Tasks.Task, Tasks.EstimatedHours, Tasks.UserStoryTaskID, Tasks_Log.TaskLogID, Tasks_Log.HoursLeft, Tasks_Log.ModifiedDate
FROM Backlog
INNER JOIN Tasks ON Backlog.UserStoryID = Tasks.UserStoryID
INNER JOIN Tasks_Log ON Tasks.UserStoryTaskID = Tasks_Log.TaskID
WHERE (Tasks.OwnershipID = #UserID)
AND (Tasks_Log.ModifiedDate =
(SELECT MAX(ModifiedDate)
FROM Tasks_Log AS Tasks_Log_1
WHERE Tasks_Log_1.TaskID = Tasks_Log.TaskID))