Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
Abraham Luna #1
gridview sorting is not working
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.ConnectionStrin gs["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>
Abraham Luna Guest
-
GridView doesn't appear
Hi, I am using the control GridView. I can see this control in html document in design view, but when I run it, it will not show up, neither the... -
Sorting not working correctly
Hey, I am trying to do the same as described here (http://www.wintellect.com/forum/topic.asp?TOPIC_ID=709). The only difference is that I have... -
GridView paging/sorting - will it work with stored procedures?
Can anyone tell me whether the new ASP.NET 2.0 GridView control supports sorting and paging when the data source is a SQL stored procedure, e.g.... -
please DataGrid vs. GridView
GridView is a more functional Control in Whidbey -
What is the GridView?
Hey Folks. Who can tell us all more about the GridView in http://msdn.microsoft.com/vstudio/productinfo/roadmap.aspx the successor to the DataGrid?... -
Sachin Saki #2
RE: gridview sorting is not working
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
"Abraham Luna" wrote:
> 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.ConnectionStrin gs["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>
>
>
>Sachin Saki Guest
-
Abraham Luna #3
Re: gridview sorting is not working
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
Abraham Luna Guest



Reply With Quote

