Click here to Skip to main content
15,937,186 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Gridview in my application
I am having a problem with it

I am using a dropdown to select a user and from which the records in Gridview will populated
when i select a user from dropdown it throws an exception "The data source does not support server-side data paging."

The code of Selecting is ==>

protected void btnok_Click(object sender, ImageClickEventArgs e)
        if (Convert.ToInt32(dropdownuser.SelectedIndex) != 0)
            DBConnection d = new DBConnection();
            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "SELECT  tblUser.FirstName, tblUser.LastName, tblUser.Designation,tblAttendance.TimeArrive, tblAttendance.TimeLeave, tblAttendance.WorkingHour, tblAttendance.DayofAttend as Day, tblAttendance.DateofAttend as Date,tblAttendance.Reasonoflate as Reason, tblAttendance.Status FROM tblAttendance INNER JOIN  tblUser ON tblAttendance.UserID = tblUser.UserId AND tblUser.UserId =" + dropdownuser.SelectedValue;
            cmd.Connection = d.myconn;
            GridView1.DataSource = cmd.ExecuteReader();
    catch (Exception ex)
        throw ex;

And the code of GridView is ==>

<asp:GridView id="GridView1" runat="server" Width="567px" ForeColor="#333333" CellPadding="4"
                            GridLines="None" Height="140px" AllowPaging="True">
<FooterStyle BackColor="#990000" ForeColor="White" Font-Bold="True"></FooterStyle>
<RowStyle BackColor="#FFFBD6" ForeColor="#333333"></RowStyle>
<SelectedRowStyle BackColor="#FFCC66" ForeColor="Navy" Font-Bold="True"></SelectedRowStyle>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center"></PagerStyle>
<HeaderStyle BackColor="#990000" ForeColor="White" Font-Bold="True"></HeaderStyle>
<AlternatingRowStyle BackColor="White"></AlternatingRowStyle>
Updated 3-Feb-11 19:22pm

Bind the gridview using sqladapter to fill a datatable or dataset
DataTable dt = new DataTable();       
        SqlDataAdapter ad1 = new SqlDataAdapter(cmd);
        GridView1.DataSource = dt;
Share this answer
Syed Salman Raza Zaidi 4-Feb-11 3:01am    
Jahan Panah Tussi Great ho :D
m@dhu 4-Feb-11 8:27am    
Glad helped you.
Espen Harlinn 6-Feb-11 11:35am    
Nice and simple, my 5
Just to elaborate more, SqlDataReader is forward only, thus does not support server side data paging and hence the error. As suggested in other answer, use DataAdapter to fill a dataset and then use it.

Similar discussions: Link 1[^], Link 2[^]
Share this answer
Espen Harlinn 6-Feb-11 11:35am    
Good advice :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900