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
Related
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">
Hello i want gridview which should be like
|Sl No|Std No|Student Name|Total Amount|Paid Amount|Unpaid Amount|Action|
Here I am setting Sl No ,Unpaid Amount , and Action Columns by Template Field.And Other i am directly getting from mysql DB and binding to gridview. But the columns from DB are apending to end of those 3 TemplateFields.And i cant use BoundFields for those 4 Fields from DB.
MY CODE IS LIKE THIS
<div class="GridviewDiv">
<asp:GridView runat="server" ID="gvDetails" AllowPaging="false" AutoGenerateColumns="true" Width="100%" OnRowDataBound="GridView1_RowDataBound1">
<HeaderStyle CssClass="headerstyle" />
<Columns>
<asp:TemplateField HeaderText="SlNo">
<ItemTemplate>
<%#Container.DataItemIndex+1 %>
<asp:Label ID="serialID" runat="server" Visible="false"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<%-- HERE I WANT THOSE COLUMNS FROM DATABASE--%>
<asp:TemplateField HeaderText="Unpaid Amount">
<ItemTemplate>
<asp:Label ID="UnpaidText" runat="server"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Take Fee">
<ItemTemplate>
<asp:Button ID="TakeFeeCash" runat="server" BackColor="#2C6AA0" BorderColor="#2C6AA0" align="right"
BorderStyle="Ridge" Font-Bold="True" ForeColor="White" OnClick="FeeCashButton_click"
Text="Take Fee" CommandName="Select" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
What i am getting is like this
IMAGE:
How to set my columns like above format?
Please Help.
I have a list view to show products with prices. I put an updatePanel in ItemTemplate.
When I Click the button in contentTemplate, the Eval fields do not update, By definition the
update panel do a partial post back but it does not reflect database changes.
<ContentTemplate>
<asp:ImageButton ID="productPic" runat="server" Height="270" Width="202" ImageUrl='<%# Eval("ImageUrl") %>' />
<asp:Table ID="ColorTable" runat="server" EnableViewState="true"></asp:Table>
<asp:Button ID="Button1" runat="server" Text="Button" />
<asp:Literal ID="LitProductId" runat="server" Text='<%# Eval("ProductId") %>' EnableViewState="true"></asp:Literal>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("Name") %>' Font-Size="8"
Font-Bold="False" Font-Names="tahoma" />
<br />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("Price","{0:0,0}") %>' Font-Size="8" Font-Bold="False" Font-Names="tahoma"
Font-Strikeout='<%# Eval("DiscountedPrice")!=DBNull.Value %>' />
<br />
<asp:Label ID="Label4" runat="server" Text='<%# Eval("DiscountedPrice","{0:0,0}") %>' Font-Size="10" Font-Bold="True" Font-Names="tahoma" ForeColor="Red"
Visible='<%# Eval("DiscountedPrice")!=DBNull.Value %>' />
<br />
</ContentTemplate>
</asp:UpdatePanel>
<br />
</td>
I appreciate any help.
It's because you are dynamically adding them in. When you post back, it loses that state and if you aren't adding them back in at that point (i.e. saving them to viewstate and adding them back in on load), it no longer knows they exist.
I found the solution.
If you want to use update panel inside a listview, you should bind the data source in code - page load.
ListView1.DataSource = new ProductFacade().GetCat3ProductListSpec(cat3Id);
ListView1.DataBind();
When you use sqlDataSource attribute, the update panel does not function as you expect.
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
I have the following Gridview which I am trying to pass a search parameter, to update the results based on that search -
<ContentTemplate>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Search" />
<asp:Label ID="Label1" runat="server" Text="Grid not refreshed yet."></asp:Label><br />
<asp:Label ID="Label4" runat="server" Text="(Grid Will Referesh after Every Second)"Font-Bold="true"></asp:Label>
<br /><br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MyDbConn %>"
SelectCommand="SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.text+"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
BackColor="Black" DataSourceID="SqlDataSource1" Font-Names="Arial Black"
Font-Size="Small" ForeColor="White" Height="650px" Width="930px">
</asp:GridView>
</ContentTemplate>
However I cant seem to get the SQL statement to accept the TextBox1 text that the user is entering, how can I resolve this?
You must do this in code behind.
SqlDataSource1.SelectCommand = "SELECT * FROM [table] WHERE BODYTEXT LIKE='"+TextBox1.Text;
You can do this when clicking on the search button.