all groups > asp.net datagrid control > august 2005 >
You're in the

asp.net datagrid control

group:

gridview sorting is not working


gridview sorting is not working Abraham Luna
8/29/2005 4:20:12 PM
asp.net datagrid control: 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>

RE: gridview sorting is not working Sachin Saki
8/30/2005 5:02:04 AM
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


[quoted text, click to view]
Re: gridview sorting is not working Abraham Luna
8/30/2005 8:34:18 AM
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

AddThis Social Bookmark Button