gridview sorting is not working

A

Abraham Luna

can anyone tell me why this code is not working, i've been following the
tutorials but i can't get it to work:

<script language="c#" runat="server">

void Page_Load (Object Sender, EventArgs E)
{
if (!Page.IsPostBack)
{
BindData(0);
}
}

void btnRefresh_Click(Object Sender, EventArgs E)
{
BindData(0);
}

void gvCustomers_PageIndexChanging(Object Sender, GridViewPageEventArgs E)
{
BindData(E.NewPageIndex);
E.Cancel = true;
}

void BindData(int intPageIndex)
{
lblSQL.Text = "SELECT [CusId], [Name], [Addr1] + '<br>' + [City] + ', ' +
[State] + ' ' + [Post] AS Address, [PhoneWork], [Contact], [EmailWork] FROM
[COCUS]";
SqlConnection connRDK = new
SqlConnection(ConfigurationManager.ConnectionStrings["TestConnection"].ToString());
SqlDataAdapter daRDK = new SqlDataAdapter(lblSQL.Text, connRDK);
DataTable dtCustomers = new DataTable();
daRDK.Fill(dtCustomers);
daRDK.Dispose();
connRDK.Close();
connRDK.Dispose();
gvCustomers.DataSource = dtCustomers;
gvCustomers.DataBind();
gvCustomers.PageIndex = intPageIndex;
gvCustomers.PageSize = Convert.ToInt32(ddlRPP.SelectedItem.Value);
lblTotal.Text = dtCustomers.Rows.Count.ToString();
lblPageIndex.Text = gvCustomers.PageIndex.ToString();
}

</script>
 
S

Sachin Saki

Hi,

daRDK.Dispose();
connRDK.Close();
connRDK.Dispose();

Use Try Catch Block and Place this 3 lines in the Finally Block.

Regards,
Sachin Saki
..NET Developer : Capgemini - INDIA
 
A

Abraham Luna

so sorry, maybe it would help if i explained what isnt working. everything
works except the gvCustomers_PageIndexChanging

it doesnt seem to call binddata

does anyone have an advanced gridview sample that uses: paging, sorting, and
filtering using webcontrols
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top