I am facing a situation where the selectcountmethod isn't called.
The getdatamethod is called every time, but the count method is not. I also tried to remove the selectcountmethod and set enablepaging="false" and no data is displayed either, even if the dataset is not empty.
<asp:GridView ID="gvGradeDocent" runat="server" AutoGenerateColumns="False" AllowPaging="True"
DataSourceID="odsGradeDocent" DataKeyNames="Id" PagerStyle-HorizontalAlign="Right"
PagerSettings-Position="Top" CssClass="table">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" SortExpression="Id" Visible="false" />
<asp:BoundField DataField="DecisionNo" HeaderText="DecisionNo" SortExpression="DecisionNo" />
<asp:BoundField DataField="DecisionDate" HeaderText="DecisionDate" SortExpression="DecisionDate"
DataFormatString="{0:dd/MM/yyyy}" />
<asp:CheckBoxField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:CommandField ShowSelectButton="True" ButtonType="Image" SelectImageUrl="~/Images/edit.png" />
<asp:CommandField ShowDeleteButton="True" ButtonType="Image" DeleteImageUrl="~/Images/delete.png" />
</Columns>
</asp:GridView>
</div>
<asp:ObjectDataSource ID="odsGradeDocent" runat="server" SelectMethod="GetDocentGrades"
TypeName="mash.BusinessLogic.DocentGrade" EnablePaging="True" DeleteMethod="Delete"
SelectCountMethod="GetCountDocentGrades"></asp:ObjectDataSource>
Try working with the code sample here:
http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdatasource.enablepaging.aspx
Check your query first to ensure that data is coming back. Also set the MaximumRowsParameterName and StartRowIndexParameterName parameters to the corresponding params in your select query.
Related
I have a grid view which display records by reading the data from a local database. I want to display a button called view with each record displayed. Simply meaning in each row there should be an asp.net button called view Details.
Here is my grid view code:
<asp:GridView ID="ItemView" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CssClass="list" DataKeyNames="ItemID"
DataSourceID="ADDataSource" GridLines="Both" Width="215px">
<Columns>
<asp:BoundField DataField="itemID" HeaderText="Item ID" />
<asp:BoundField DataField="Item Name" HeaderText="Item Name" />
<asp:BoundField DataField="Item Brand" HeaderText="Item Brand" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
</Columns>
</asp:GridView>
I have added a button to delete records and edit records through common field property, but how do i add my own button called view to display in each row as the other 2 buttons.
Thank you.
I managed do it myself.
<asp:BoundField DataField="topic" HeaderText="Topic Name" />
<asp:BoundField DataField="Brand" HeaderText="Vehicle Brand" />
<asp:BoundField DataField="Model" HeaderText="Vehicle Model" />
<asp:BoundField DataField="Year" HeaderText="Vehicle Year" />
<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />
<asp:TemplateField ShowHeader="False">
<ItemTemplate>
<asp:Button ID="viewDetails" runat="server" Text="View" />
</ItemTemplate>
</asp:TemplateField>
I want to hide a column in a gridview. I use the following code;
dgvTekleme.Columns[1].Visible = false;
but this does not work. (may be it does not work because of using that column in the code)
Is there any solution to hide a column in code-behind
you can do this manually.....
goto asp:gridview tag and in gridview tag set autogeneratecolumn="false"
if you don't want to display some column just don't write that column....
for example if you don't want to display prodId column just erase that line....
and write manually for displaying data like!!!!!!!!!!
<asp:GridView ID="gridview1" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="ProdID" DataField="prodid" ReadOnly="true" />
<asp:BoundField HeaderText="ProdName" DataField="ProdName" />
<asp:BoundField HeaderText="Quantity" DataField="quantity" />
<asp:BoundField HeaderText="SupplierID" DataField="SupplierId" />
<asp:BoundField HeaderText="StockLvl" DataField="stocklevel" />
<asp:BoundField HeaderText="MinStockLvl" DataField="minstocklevel" />
<asp:BoundField HeaderText="CostPrice" DataField="costprice" />
<asp:BoundField HeaderText="SalesPrice" DataField="saleprice" />
<asp:BoundField HeaderText="Loc" DataField="location" />
<asp:BoundField HeaderText="ProdCode" DataField="prodtypecode" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="true" />
</Columns>
</asp:GridView>
or you can check this link:
How to hide columns in an ASP.NET GridView with auto-generated columns?
I would like to validate columns in an asp:Gridview but am unsure how to do so as all the tutorials I have found show a previous version on Microsoft Visual Studio (I am using 2010).
How do I validate each column of the Gridview?
Thanks
This is the code of my Gridview generated by visual studio.
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False"
DataKeyNames="registrationNo" DataSourceID="SqlDataSource3"
onselectedindexchanged="GridView2_SelectedIndexChanged">
<Columns>
<asp:BoundField DataField="fullName" HeaderText="fullName"
SortExpression="fullName" />
<asp:BoundField DataField="address" HeaderText="address"
SortExpression="address" />
<asp:BoundField DataField="work" HeaderText="work"
SortExpression="work" />
<asp:BoundField DataField="home" HeaderText="home" SortExpression="home" />
<asp:BoundField DataField="mobile" HeaderText="mobile"
SortExpression="mobile" />
<asp:BoundField DataField="registrationNo" HeaderText="registrationNo"
InsertVisible="False" ReadOnly="True" SortExpression="registrationNo" />
<asp:ButtonField ButtonType="Button" CommandName="Edit" HeaderText="Edit"
ShowHeader="True" Text="Edit" />
<asp:ButtonField ButtonType="Button" CommandName="Update" HeaderText="Update"
ShowHeader="True" Text="Update" />
<asp:ButtonField ButtonType="Button" CommandName="Delete" HeaderText="Delete"
ShowHeader="True" Text="Delete" />
</Columns>
<HeaderStyle BorderColor="#33CC33" />
<RowStyle BorderStyle="Double" Font-Names="Monotype Corsiva" />
</asp:GridView>
//native asp.net clientside validation (ATLAS Ajax)
Instead of using BoundFields you should use TemplateField. This will allow you to add Validation controls in the field i.e.
Tutorial from 2007 which is still pertinent to this question
//serverside validation
In order to validate the values on the server side you have a couple of options:
a) add a CustomValidator pointing to codebehind server validation method i.e. msdn doc
b) on the gridviews RowUpdating method you could validate manually (this would also be for batch updates)
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>
I have gridview that I am using paging on. I want to pass along the current page in a asp:Hyperlink so I can send them back to the current page when they are done viewing the details of a record. Is this possible? If it is how can I do this?
<asp:GridView ID="grdObitList" runat="server" allowpaging="true"
PageSize="10" AutoGenerateColumns="false" CssClass="grdClass"
BorderStyle="None" GridLines="None" CellSpacing="2" >
<PagerStyle HorizontalAlign="Center" />
<PagerSettings Position="Bottom" FirstPageText="First" LastPageText="Last" Mode="NumericFirstLast" />
<Columns>
<asp:HyperLinkField HeaderText="Name" DataTextField="obit_fullname" DataNavigateUrlFields="obit_id" DataNavigateUrlFormatString="obitDisplay.aspx?oid={0}" />
<asp:BoundField ReadOnly="true" HeaderText="Date" DataField="obit_dod" DataFormatString="{0:d/M/yyyy}" />
<asp:BoundField ReadOnly="true" HeaderText="Resident Of" DataField="obit_resident" />
<asp:BoundField ReadOnly="true" HeaderText="Funeral Home" DataField="obit_funeralhome" />
</Columns>
One way to do it is converting it to a template column, that way you can use normal databind syntaxt to get to it (<%#)