Gridview Paging is always on - asp.net

I want to turn paging off on a gridview, however, I can't seem to turn it off and I don't understand hwy it is on to begin with.
This seems like such a basic issue, but I can't seem to find anyone having the same issue. I can find plenty of people having issues in turning paging on, but no one turning it off.
ASP.Net Code
<asp:TabContainer ID="tcQuestions" runat="server" Width="100%" ActiveTabIndex="2">
<asp:TabPanel ID="tpAll" runat="server" HeaderText="All Questions" ScrollBars="None">
<ContentTemplate>
<asp:UpdatePanel ID="upAll" runat="server">
<ContentTemplate>
<asp:GridView ID="gvAllQuestions" runat="server" DataSourceID="sdsQuestions" AutoGenerateColumns="False" AllowPaging="False" Width="100%">
<Columns>
<asp:HyperLinkField DataTextField="QuestionRef" HeaderText="Ref" DataNavigateUrlFields="FkSection,QuestionID" DataNavigateUrlFormatString="questions/{0}/{1}">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:HyperLinkField>
<asp:BoundField DataField="QuestionText" HeaderText="Question" />
<asp:BoundField DataField="Period" HeaderText="Frequency">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ValidFrom" HeaderText="Start From" DataFormatString="{0:dd MMM yy}">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
<asp:BoundField DataField="ObsoleteDate" HeaderText="Next Review" DataFormatString="{0:dd MMM yy}">
<HeaderStyle Wrap="False" />
<ItemStyle Wrap="False" />
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="sdsQuestions" runat="server"
ConnectionString="<%$ ConnectionStrings:ApplicationConnectionString %>"
SelectCommand="SELECT QuestionID, QuestionRef, QuestionText, FkSection, Period, ValidFrom, ObsoleteDate FROM Questions WHERE [FkSection] = #SectionID ORDER BY Obsolete, ObsoleteDate Desc">
<SelectParameters>
<asp:ControlParameter ControlID="ddlSections" Name="SectionID" />
</SelectParameters>
</asp:SqlDataSource>
</ContentTemplate>
</asp:UpdatePanel>
</ContentTemplate>
</asp:TabPanel>
There is no code behind affecting the gridview.

Related

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.

Getting invalid character error when deleting a gridview row

I was assigned to convert some .Net projects in old version to to .net 4.0 version. I used ODAC driver replacing ODBC driver. Everything went fine until I found a problem with a gridview were I get illegal character Oracle exception when I try to delete a row. The gridview is inside an update panel. The exception I receive is Microsoft Jscript run time error:Sys.WebForms.PageRequestManagerServerErrorException: ORA-00911:invalid character. The following is the code for the grid view and the sqldatasource. The linkbutton triggers the delete using the deleteparameters of the sqldatasource.
<FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:TemplateField HeaderText="View">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("CODE_OWNER_ID", "default.aspx?id={0}") %>'>View</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="CODE_OWNER_ID" Visible ="False" HeaderText="CODE OWNER ID" />
<asp:BoundField DataField="CODE_TYPE" ReadOnly ="True" HeaderText="CODE TYPE" />
<asp:BoundField DataField="CODE" ReadOnly="True" HeaderText="CODE" />
<asp:BoundField DataField="UNIT_CODE" ReadOnly ="True" HeaderText="UNIT CODE" />
<asp:BoundField DataField="UNIT_NAME" ReadOnly="True" HeaderText="UNIT NAME" />
<asp:BoundField DataField="UNIT_DO" ReadOnly="True" HeaderText="UNIT DO" />
<asp:BoundField DataField="OWNER" ReadOnly="True" HeaderText="OWNER" />
<asp:BoundField DataField="OWNER_EMAIL" ReadOnly="True" HeaderText="OWNER EMAIL" />
<asp:BoundField DataField="OWNER_PHONE" ReadOnly="True" HeaderText="OWNER PHONE" />
<asp:BoundField DataField="OWNER_MAILPOINT" ReadOnly="True" HeaderText="OWNER MAILPOINT" />
<asp:BoundField DataField="CODE_ESTABLISHED_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="CODE ESTABLISHED DATE" />
<asp:BoundField DataField="LAST_REVIEW_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="LAST REVIEW DATE" />
<asp:BoundField DataField="REVIEW_USERNAME" ReadOnly="True" HeaderText="REVIEW USERNAME" />
<asp:BoundField DataField="CODE_DELETED_DATE" ReadOnly="True" DataFormatString="{0:MM/dd/yyyy}" HeaderText="CODE DELETED DATE" />
<asp:BoundField DataField="DELETE_REASON" ReadOnly="True" HeaderText="DELETE REASON" />
<asp:BoundField DataField="UPDATE_USERNAME" ReadOnly="True" HeaderText="UPDATE USERNAME" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:LinkButton ID="LinkButton2" runat="server" CausesValidation="False" CommandName="Delete"
Text='Delete'
OnClientClick="return confirm('Are you sure you want to delete this record?');"
CommandArgument='<%# bind("CODE_OWNER_ID") %>'></asp:LinkButton>
</ItemTemplate>
<ItemStyle Wrap="False" />
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#FFCC66" ForeColor="Navy" Font-Bold="True" />
<HeaderStyle BackColor="#990000" Font-Bold="True" HorizontalAlign="Center" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnAdd" />
</Triggers>
</asp:UpdatePanel>
<asp:SqlDataSource ID="Sqldatasource1" runat="server" ConnectionString="<%$ ConnectionStrings:Conn_Code_Owner %>"
ProviderName="<%$ ConnectionStrings:Conn_Code_Owner.ProviderName %>"
OldValuesParameterFormatString="original_{0}"
SelectCommand="SELECT * FROM CODE_OWNER"
DeleteCommand="DELETE FROM CODE_OWNER WHERE CODE_OWNER_ID = ?"
OnSelecting="_data_Selecting"
ConflictDetection="CompareAllValues" >
<DeleteParameters>
<asp:Parameter Name="Original_CODE_OWNER_ID" Type="Decimal"/>
</DeleteParameters>
</asp:SqlDataSource>
Try and wrap it w/ a Begin and End
BEGIN CODE_OWNER WHERE CODE_OWNER_ID = ? END
http://www.lazyasscoder.com/Article.aspx?id=89&title=ora-00911%3A+invalid+character+when+executing+multiple+Oracle+SQL+statements
I found an easy alternative using row-deleting event of the grid-view. I Just removed the delete parameters in the sqldatasource of asp page and then I set conflict-detection to overwrite-changes.
Sqldatasource1.DeleteCommand = "DELETE FROM code_owner WHERE code_owner_ID = :original_code_owner_ID"
Sqldatasource1.DeleteParameters.Add("original_code_owner_ID", GridView1.DataKeys(e.RowIndex).Values("code_owner_ID").ToString)
Sqldatasource1.Delete()
GridView1.DataBind()

Question about ASP.NET gridviews

I have a gridview. Is it possible to modify the gridview so that I can have multiple rows in the column headers? For example, the following code generates the table in the picture below.
<asp:GridView ID="productsGridView" Runat="server" DataSourceID="productDataSource" AutoGenerateColumns="False" AllowSorting="True" BorderWidth="2px"
BackColor="White" GridLines="None" CellPadding="3" CellSpacing="1" BorderStyle="Ridge" BorderColor="White" AllowPaging="True">
<FooterStyle ForeColor="Black" BackColor="#C6C3C6"></FooterStyle>
<PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#C6C3C6"></PagerStyle>
<HeaderStyle ForeColor="#E7E7FF" Font-Bold="True" BackColor="#4A3C8C"></HeaderStyle>
<Columns>
<asp:BoundField HeaderText="Product" DataField="ProductName" SortExpression="ProductName"></asp:BoundField>
<asp:BoundField HeaderText="Unit Price" DataField="UnitPrice" SortExpression="UnitPrice" DataFormatString="{0:c}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Units In Stock" DataField="UnitsInStock" SortExpression="UnitsInStock" DataFormatString="{0:d}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Quantity Per Unit" DataField="QuantityPerUnit"></asp:BoundField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#9471DE"></SelectedRowStyle>
<RowStyle ForeColor="Black" BackColor="#DEDFDE"></RowStyle>
</asp:GridView>
This table only has one row in the column header. What I am looking for is something like this:
Any Ideas on how I can achieve this? Is this even possible?
If you use a TemplateField instead, you can control the header template as well, which can be custom ASPX markup. The downside is that you have to display the data manually with Labels instead of using the simpler BoundField properties. However, this also allows you to layout the data in a custom layout to fit with the heading:
<Columns>
<asp:TemplateField>
<HeaderTemplate>
Weight<br />
Date | Time<br />
Product
</HeaderTemplate>
<ItemTemplate>
<asp:Label runat="server" Text='<%#Eval("Weight") %>'></asp:Label><br />
<asp:Label runat="server" Text='<%#Eval("Date") %>'></asp:Label> |
<asp:Label runat="server" Text='<%#Eval("Time") %>'></asp:Label><br />
<asp:Label runat="server" Text='<%#Eval("Product") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>

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