GridView delete command not firing in server. Locally works - asp.net

I have this gridview, that works perfectly when running in local computer. Platform is VWD 2010 - Sql Server
<asp:GridView ID="Gv_Usuarios" runat="server"
AutoGenerateColumns="False"
DataKeyNames="Login,ID" DataSourceID="SqlDataSource1" EnableModelValidation="True"
Width="619px">
<Columns>
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" runat="server"
CausesValidation="False" CommandName="Delete" OnClientClick='if
(!confirm("Borra?")) return false;' Text="Delete" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Tipo" HeaderText="Tipo" SortExpression="Tipo" />
<asp:BoundField DataField="Nombre" HeaderText="Nombre" SortExpression="Nombre" />
<asp:BoundField DataField="Login" HeaderText="Login" ReadOnly="True"
SortExpression="Login" />
<asp:BoundField DataField="Password" HeaderText="Password"
SortExpression="Password" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:BoundField DataField="Vendedor" HeaderText="Vendedor"
SortExpression="Vendedor" />
<asp:BoundField DataField="Sucursal" HeaderText="Sucursal"
SortExpression="Sucursal" />
<asp:BoundField DataField="Almacen" HeaderText="Almacen"
SortExpression="Almacen" />
<asp:BoundField DataField="Fecha" HeaderText="Fecha" SortExpression="Fecha" />
<asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False"
ReadOnly="True" SortExpression="ID" />
</Columns>
</asp:GridView>
Browser fire the confirmation question, but after hittting YES, nothing happens.
It works fine in my computer, nothing happens in the hosting server.
Thanks in advance.

Use asp:Button instead of asp:LinkButton

Related

How to Display 7 days of the week in Gridview Header from a Calendar

I am trying to display the 7 days of the week inside GridView header so my code below shows how to get those days but I don't know how to put them in Gridview Header
with day of names of the week. About like image shows. I run ASP.NET with SQL SERVER EXPRESS database use sqldatasource connection to select all employees to a gridview.
foreach (DateTime selectedDateTime in Calendar1.SelectedDates)
{
Response.Write(selectedDateTime.ToShortDateString() + " <br/>");
}
You can create the columns in the GridView this way:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:BoundField DataField="Monday" HeaderText="Monday" />
<asp:BoundField DataField="Thuesday" HeaderText="Thuesday" />
<asp:BoundField DataField="Wednesday" HeaderText="Wednesday" />
<asp:BoundField DataField="Thursday" HeaderText="Thursday" />
<asp:BoundField DataField="Friday" HeaderText="Friday" />
<asp:BoundField DataField="Saturday" HeaderText="Saturday" />
<asp:BoundField DataField="Sunday" HeaderText="Sunday" />
</Columns>
</asp:GridView>
If no data is expected in the days of the week columns, you could use TemplateFields:
<asp:GridView ID="GridView1" runat="server" ShowHeader="true" ShowHeaderWhenEmpty="true" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="EmployeeID" HeaderText="EmployeeID" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" />
<asp:TemplateField HeaderText="Monday" />
<asp:TemplateField HeaderText="Thuesday" />
<asp:TemplateField HeaderText="Wednesday" />
<asp:TemplateField HeaderText="Thursday" />
<asp:TemplateField HeaderText="Friday" />
<asp:TemplateField HeaderText="Saturday" />
<asp:TemplateField HeaderText="Sunday" />
</Columns>
</asp:GridView>

How to display a message when GridView isn't populated

I'm building a GridView based on what is passed on the previous page querystring.
Is there a way to display a message saying 'no records found' if the GridView isn't populated? i.e. the query produces no records to populate the GridView.
code:
<div class="centergrid">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ChinatowndbConnString %>"
SelectCommand="SELECT * FROM [vwSchedule] Where TourId=#tid">
<SelectParameters>
<asp:QueryStringParameter DbType="Int32" Name="tid" QueryStringField="tourid" />
</SelectParameters>
</asp:SqlDataSource>
Is there a way to display a message saying 'no records found' if the
GridView isn't populated?
Yes, with the EmptyDataTemplate.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataSourceID="SqlDataSource1" CssClass="bookgridview">
<emptydatarowstyle backcolor="LightBlue"
forecolor="Red"/>
<emptydatatemplate>
<asp:image id="NoDataImage"
imageurl="~/images/Image.jpg"
alternatetext="No Image"
runat="server"/>
No records found.
</emptydatatemplate>
<Columns>
<asp:TemplateField HeaderText="Choose">
<ItemTemplate>
<asp:HyperLink ID="lnkSelect" runat='server' NavigateUrl='<%# String.Format("~/bookingform.aspx?ID={0}", Eval("ScheduleId")) %>'>Book</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="TName" HeaderText="Name" SortExpression="TName" />
<asp:BoundField DataField="SDate" HeaderText="Date" SortExpression="SDate" DataFormatString="{0:d}" />
<asp:BoundField DataField="STime" HeaderText="Time" SortExpression="STime" />
<asp:BoundField DataField="TPriceadult" HeaderText="Price (Adult)"
SortExpression="TPriceadult" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricesenior" HeaderText="Price (Student/Senior)"
SortExpression="TPricesenior" DataFormatString="{0:C}" />
<asp:BoundField DataField="TPricechild" HeaderText="Price (Child)"
SortExpression="Tpricechild" DataFormatString="{0:C}" />
<asp:BoundField DataField="TDuration" HeaderText="Duration"
SortExpression="TDuration" />
<asp:BoundField DataField="ScheduleId" HeaderText="ScheduleId"
SortExpression="ScheduleId" Visible="False" />
</Columns>
</asp:GridView>
Alternatively, you can use the built-in UI for the empty data row by setting the EmptyDataText property instead of this property.

"An entry with the same key already exists" appears when compiled under .NET 4

I am trying to upgrade an ASP.NET application to .NET 4, but one page on my site contains an exception:
Argument Exception: an entry with the same key already exists".
What is different about ASP.NET 4 that might cause this problem?
One Solution
Not sure why but setting clientIDMode="Predictable" rather than Static seems to have avoided this exception message.
I had the same issue and fixed it.
I went through my entire ASPX page and found ASP.NET control that had the same ID as another.
I also tested this fix, and found that any control that conflicts with another control on the page will cause this error.
<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />
<asp:Label ID="FailureText" runat="server" EnableViewState="False" ClientIDMode="Static" />
It happens when you Copy/Paste elements on the same page.
This in your web.config may also cause the error by allowing duplicate IDs
<pages clientIDMode="Static">
I have this error too and not resolve with this
<pages clientIDMode="Static">
my datagrid work fine this :
I have gridview :
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
<ControlStyle CssClass="btn btn-xs btn-default" />
<ItemStyle Width="143px" />
</asp:CommandField>
<asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
<asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
<asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
<ItemStyle CssClass="ltr"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />
<asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />
</Columns>
</asp:GridView>
but after add image field i see this error
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
<Columns>
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ButtonType="Button" CancelText="لغو" DeleteText="حذف" EditText="ويرايش" UpdateText="بروزرساني">
<ControlStyle CssClass="btn btn-xs btn-default" />
<ItemStyle Width="143px" />
</asp:CommandField>
<asp:ImageField ReadOnly="true" SortExpression="Icon" DataImageUrlField="icon">
</asp:ImageField>
<asp:BoundField DataField="ID" HeaderText="#" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
<asp:BoundField DataField="Title" HeaderText="عنوان" SortExpression="Title" />
<asp:BoundField DataField="ParentID" HeaderText="پدر" SortExpression="ParentID" />
<asp:BoundField DataField="Url" HeaderText="آدرس" SortExpression="Url">
<ItemStyle CssClass="ltr"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="Icon" HeaderText="آيکون" SortExpression="Icon" />
<asp:BoundField DataField="Order" HeaderText="اولويت" SortExpression="Order" />
</Columns>
</asp:GridView>

Help with ASP.NET ObjectDataSource

I have a User object with a Load method that takes in a UserId parameter and loads that users data to the objects member variables.
Now what I'd like to do is load this data to a DetailsView control using an ObjectDataSource, but I'm stumped as to how.
First of all, I'm not sure I've got the code set up properly to pass the parameter (UserID) to the SelectMethod (cUser.Load). Secondly, I don't know how I can load this data to the DetailsView since I'm not actually returning the results from the Load method, I'm simply loading the object with the data...here's my code..
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleting="GridView1_RowDeleting"
OnSelectedIndexChanged="IndexChanged" >
<HeaderStyle BackColor="Black" ForeColor="White"
Font-Bold="True" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="yellow" ForeColor="blue" />
<AlternatingRowStyle BackColor="#ffffff" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Select" runat="server">
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="ObjectDataSource1" AutoGenerateRows="False" Width="85%"
HorizontalAlign="Center" DataKeyNames="UserID" >
<Fields>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="Birthdate" HeaderText="Birthdate" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="ynAdminUser" HeaderText="ynAdminUser" />
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True" ShowInsertButton="True" />
>
</Fields>
</asp:DetailsView>
<asp:ObjectDataSource ID="ObjectDataSource1"
runat="server" SelectMethod="Load" TypeName="cUser">
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" PropertyName="SelectedValue" Name="iUserID" Type="int32" />
</SelectParameters>
</asp:ObjectDataSource>
is there a way to do what I'm trying to achieve? if so, can you please give examples with the explanation?
Very much appreciated. Thanks
you need to check this tutorial for detail help....
Master/Detail Using a Selectable Master GridView with a Details DetailView

Using a detailsview without sqldatasource

I have a Detailsview object that is loaded with user data when a User is clicked from a gridview. The problem is, I am using a sqldatasource and I'd rather use my pre-exisiting user class which has all the built in functionality for this. I haven't been able to get this done correctly. I can't get the detailsview populated with user data without the sqldatasource, and when I try inserting or updating with my objects, it runs through the insert/update code, then fails afterwards because I don't have a InsertCommand, etc for my SQLDataSource....bottom line...can somebody help me get this working without needing the SQLDataSource?
Here's my code.
<asp:GridView runat="server" ID="gvUsers" DataKeyNames="UserID" BackColor="#eeeeee" Width="85%"
HorizontalAlign="Center"
Font-Bold="True" Font-Names="Verdana"
Font-Size="10pt" AutoGenerateColumns="False"
OnRowDataBound="GridView1_RowDataBound"
OnRowDeleting="GridView1_RowDeleting" >
<HeaderStyle BackColor="Black" ForeColor="White"
Font-Bold="True" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="yellow" ForeColor="blue" />
<AlternatingRowStyle BackColor="#ffffff" />
<Columns>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="LinkButton2"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Select" runat="server">
Select</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:TemplateField HeaderText="Delete?">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1"
CommandArgument='<%# Eval("UserID") %>'
CommandName="Delete" runat="server">
Delete</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView><br /><br />
<asp:DetailsView runat="server" ID="dvUser" DataSourceID="SqlDataSource3" AutoGenerateRows="False" Width="85%"
HorizontalAlign="Center" DataKeyNames="UserID">
<Fields>
<asp:BoundField DataField="UserID" Visible="false" />
<asp:BoundField DataField="FirstName" HeaderText="First Name" />
<asp:BoundField DataField="LastName" HeaderText="Last Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Password" HeaderText="Password" />
<asp:BoundField DataField="Birthdate" HeaderText="Birthdate" />
<asp:BoundField DataField="Address" HeaderText="Address" />
<asp:BoundField DataField="Apt" HeaderText="Apt" />
<asp:BoundField DataField="City" HeaderText="City" />
<asp:BoundField DataField="Province" HeaderText="Province" />
<asp:BoundField DataField="PostalCode" HeaderText="PostalCode" />
<asp:BoundField DataField="PhoneNum" HeaderText="PhoneNum" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="ynAdminUser" HeaderText="ynAdminUser" />
<asp:CommandField ShowDeleteButton="False" ShowEditButton="True" ShowInsertButton="True" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ConnectionString="<%$ ConnectionStrings:ConnectionString%>" ID="SqlDataSource3"
runat="server" SelectCommand="sp_GetUser" SelectCommandType="StoredProcedure" OnInserting="OnInserting" >
<SelectParameters>
<asp:ControlParameter ControlID="gvUsers" Name="UserID" PropertyName="SelectedValue" Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>
Not sure the CodeBehind is necessary, I just want to use that to call my data object code for updating, insert etc
Why not use a ObjectDataSource. This control works much like an SqlDataSource but instead of specifying an SQL query or Stored Procedure you specify the methods of your custom business object to perform your data access.
<asp:ObjectDataSource ID="ObjectDataSource" Drunat="server" DeleteMethod="Delete" InsertMethod="Insert" SelectMethod="Select" UpdateMethod="Update" TypeName="YourType">
Here's an example illustrating how to use an ObjectDataSource with a DetailsView.

Resources