C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




error.


Posted Date: 17 Jul 2008      Total Responses: 2

Posted By: sreemani       Member Level: Gold     Points: 1



i wrote source code.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CellPadding="4"
ForeColor="#333333" GridLines="None" Style="z-index: 100; left: 121px; position: absolute;
top: 174px" OnRowDeleting="GridView1_RowDeleting" AllowPaging="True" PageSize="5" HorizontalAlign="Center" OnPageIndexChanging="GridView1_PageIndexChanging" EnableSortingAndPagingCallbacks="True">
<FooterStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#E3EAEB" />
<EditRowStyle BackColor="#7C6F57" />
<SelectedRowStyle BackColor="#C5BBAF" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#666666" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#1C5E55" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" />
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="Chk1" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="EMPID" HeaderText="EMPID" SortExpression="EMPID" />
<asp:BoundField DataField="EMP_NAME" HeaderText="EMPNAME" SortExpression="EMPNAME" />
<asp:BoundField DataField="DEPID" HeaderText="DEPID" SortExpression="DEPID" />
<asp:CommandField HeaderText="DELETE" ShowDeleteButton="True" />


</Columns>
<EmptyDataRowStyle HorizontalAlign="Center" />
</asp:GridView>
   
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Style="z-index: 101;
left: 135px; position: absolute; top: 124px" Text="SelectAll" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click" Style="z-index: 102;
left: 248px; position: absolute; top: 125px" Text="ClearAll" />
<asp:Button ID="Button3" runat="server" OnClick="Button3_Click" Style="z-index: 103;
left: 341px; position: absolute; top: 123px" Text="GetEmpName" />
<asp:Label ID="Label1" runat="server" Style="z-index: 104; left: 154px; position: absolute;
top: 66px" Text="Label"></asp:Label>
<asp:Label ID="Label2" runat="server" Style="z-index: 105; left: 151px; position: absolute;
top: 28px" Text="Label"></asp:Label>
</div>
</form>
</body>
</html>



i wrote code like that


SqlConnection con = new SqlConnection(ConfigurationSettings.AppSettings.Get("Constring1"));
string name = string.Empty;

protected void Page_Load(object sender, EventArgs e)
{

if (!IsPostBack)
{
GetGridValues();
}

}
protected void GetGridValues()
{
con.Open();
string str = "select empid,emp_name,depid from employee";
SqlCommand cmd = new SqlCommand(str, con);
SqlDataReader dr = cmd.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
con.Close();
}

but , i got this error.


The data source does not support server-side data paging.








Responses

Author: vipul    17 Jul 2008Member Level: DiamondRating:     Points: 5

Hi,
You used this way
protected void GetGridValues()
{
con.Open();
string str = "select empid,emp_name,depid from employee";
SqlCommand cmd = new SqlCommand(str, con);
DataSet ds = cmd.ExecuteReader();
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();
}

here for binding any data bind control you used dataset or datatable not datareader

vipul,
http://dongavipul.blogspot.com

Patel Vipul
Web Developer
Ahmedabad ( Gujarat )



Author: Koteswara Rao    17 Jul 2008Member Level: GoldRating:     Points: 6

You have made the mistake-the datasource is an "OdbcDataReader" and a Reader don't support paging.

Fill first a DataSet or DataTable and bind it then as DataSource

then paging will work out

protected void GetGridValues()
{

con.Open();
string str = "select empid,emp_name,depid from employee";
SqlCommand cmd = new SqlCommand(str, con);
DataSet resultDs = new DataSet();
SqlDataAdapter dataAdapter = null;
dataAdapter = new SqlDataAdapter(str , con);
dataAdapter.Fill(resultDs);
GridView1.DataSource = resultDs;
GridView1.DataBind();
con.Close();
}

Now will work






Post Reply
You must Sign In to post a response.
Next : Insert record from datatable to database or gridview to database
Previous : resource cannot be found error while running
Return to Discussion Forum
Post New Message
Category: ASP.NET

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use