473,378 Members | 1,370 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Data Grid NOT SORTING

Hi,

I am using teh following code for sorting the data grid but it doesnt work.
I have set the auto generate columns to false. & set the sort expression for
each field as the anme of that field... This grid displayes results based on
users search..

public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
if( (numberDiv%2) == 0 )
dv.Sort = e.SortExpression + " " + "ASC";
else
dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}
}
--
pmud
Jul 21 '05 #1
12 2354
Add a space character into the ASC and DESC strings (" ASC" and " DESC").
If you don't then the sort criteria gets ASC or DESC cocatenated right onto
the end of the sort string.
"pmud" <pm**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi,

I am using teh following code for sorting the data grid but it doesnt
work.
I have set the auto generate columns to false. & set the sort expression
for
each field as the anme of that field... This grid displayes results based
on
users search..

public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
if( (numberDiv%2) == 0 )
dv.Sort = e.SortExpression + " " + "ASC";
else
dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}
}
--
pmud

Jul 21 '05 #2
Hi Scott,

I tried that But it didnt work...Any other ideas?

Thanks

"Scott M." wrote:
Add a space character into the ASC and DESC strings (" ASC" and " DESC").
If you don't then the sort criteria gets ASC or DESC cocatenated right onto
the end of the sort string.
"pmud" <pm**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi,

I am using teh following code for sorting the data grid but it doesnt
work.
I have set the auto generate columns to false. & set the sort expression
for
each field as the anme of that field... This grid displayes results based
on
users search..

public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
if( (numberDiv%2) == 0 )
dv.Sort = e.SortExpression + " " + "ASC";
else
dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}
}
--
pmud


Jul 21 '05 #3
Can you check the value of numberDiv?
Can you also double-check you SortExpression value?

"pmud" wrote:
Hi Scott,

I tried that But it didnt work...Any other ideas?

Thanks

"Scott M." wrote:
Add a space character into the ASC and DESC strings (" ASC" and " DESC").
If you don't then the sort criteria gets ASC or DESC cocatenated right onto
the end of the sort string.
"pmud" <pm**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
Hi,

I am using teh following code for sorting the data grid but it doesnt
work.
I have set the auto generate columns to false. & set the sort expression
for
each field as the anme of that field... This grid displayes results based
on
users search..

public static int numberDiv;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
if( (numberDiv%2) == 0 )
dv.Sort = e.SortExpression + " " + "ASC";
else
dv.Sort = e.SortExpression + " " + "DESC";
numberDiv++;
DataGrid1.DataSource = dv;
DataGrid1.DataBind();
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}
}
--
pmud


Jul 21 '05 #4
HI,

Can you plz tell me how to use sorting with the folowing code?
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

Plz help. I am struggling with it since some days now....

Thanks

"jwkjng" wrote:
Can you check the value of numberDiv?
Can you also double-check you SortExpression value?

"pmud" wrote:
Hi Scott,

I tried that But it didnt work...Any other ideas?

Thanks

"Scott M." wrote:
Add a space character into the ASC and DESC strings (" ASC" and " DESC").
If you don't then the sort criteria gets ASC or DESC cocatenated right onto
the end of the sort string.
"pmud" <pm**@discussions.microsoft.com> wrote in message
news:83**********************************@microsof t.com...
> Hi,
>
> I am using teh following code for sorting the data grid but it doesnt
> work.
> I have set the auto generate columns to false. & set the sort expression
> for
> each field as the anme of that field... This grid displayes results based
> on
> users search..
>
> public static int numberDiv;
> private void Page_Load(object sender, System.EventArgs e)
> {
> // Put user code to initialize the page here
> }
> private void btnSearch_Click(object sender, System.EventArgs e)
> {
> fn();
> sqlDataAdapter1.Fill(dsSearch1);
>
> DataGrid1.DataBind();
> }
>
> private void DataGrid1_SortCommand(object source,
> System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> {
> fn();
> sqlDataAdapter1.Fill(dsSearch1);
> DataView dv = new DataView(dsSearch1.Tables[0]);
> if( (numberDiv%2) == 0 )
> dv.Sort = e.SortExpression + " " + "ASC";
> else
> dv.Sort = e.SortExpression + " " + "DESC";
> numberDiv++;
> DataGrid1.DataSource = dv;
> DataGrid1.DataBind();
> }
> private void fn()
> {
> sqlSelectCommand1.Parameters.Clear();
> SqlParameter order=
> sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> if (txtOrder.Text.Equals(String.Empty))
> {
> order.Value=System.DBNull.Value;
> }
> else
> {
> order.Value=int.Parse(txtOrder.Text);
> }
> SqlParameter startdate=
> sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> if (txtStartDate.Text.Equals(String.Empty) )
> {
> startdate.Value=System.DBNull.Value;
> }
> else
> {
> startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> }
> SqlParameter enddate=
> sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> if (txtEndDate.Text.Equals(String.Empty) )
> {
> enddate.Value=System.DBNull.Value;
> }
> else
> {
> enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> }
> SqlParameter status=
> sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> if (txtEndDate.Text.Equals(String.Empty) )
> {
> status.Value=System.DBNull.Value;
> }
> else
> {
> status.Value=ddlStatus.SelectedValue;
> }
> }
> }
> --
> pmud

Jul 21 '05 #5
Can you put the html for that code-behind as well?

You might want to check if you added the "onsortcommand" field.

The reason i asked for the numberDiv value is that the value might not be
incremented each time you do sorting. I would normally use "ViewState" to
store the order of sorting and flip it each time the sort command is called.
"pmud" wrote:
HI,

Can you plz tell me how to use sorting with the folowing code?
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

Plz help. I am struggling with it since some days now....

Thanks

"jwkjng" wrote:
Can you check the value of numberDiv?
Can you also double-check you SortExpression value?

"pmud" wrote:
Hi Scott,

I tried that But it didnt work...Any other ideas?

Thanks

"Scott M." wrote:

> Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> the end of the sort string.
>
>
> "pmud" <pm**@discussions.microsoft.com> wrote in message
> news:83**********************************@microsof t.com...
> > Hi,
> >
> > I am using teh following code for sorting the data grid but it doesnt
> > work.
> > I have set the auto generate columns to false. & set the sort expression
> > for
> > each field as the anme of that field... This grid displayes results based
> > on
> > users search..
> >
> > public static int numberDiv;
> > private void Page_Load(object sender, System.EventArgs e)
> > {
> > // Put user code to initialize the page here
> > }
> > private void btnSearch_Click(object sender, System.EventArgs e)
> > {
> > fn();
> > sqlDataAdapter1.Fill(dsSearch1);
> >
> > DataGrid1.DataBind();
> > }
> >
> > private void DataGrid1_SortCommand(object source,
> > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > {
> > fn();
> > sqlDataAdapter1.Fill(dsSearch1);
> > DataView dv = new DataView(dsSearch1.Tables[0]);
> > if( (numberDiv%2) == 0 )
> > dv.Sort = e.SortExpression + " " + "ASC";
> > else
> > dv.Sort = e.SortExpression + " " + "DESC";
> > numberDiv++;
> > DataGrid1.DataSource = dv;
> > DataGrid1.DataBind();
> > }
> > private void fn()
> > {
> > sqlSelectCommand1.Parameters.Clear();
> > SqlParameter order=
> > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > if (txtOrder.Text.Equals(String.Empty))
> > {
> > order.Value=System.DBNull.Value;
> > }
> > else
> > {
> > order.Value=int.Parse(txtOrder.Text);
> > }
> > SqlParameter startdate=
> > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > if (txtStartDate.Text.Equals(String.Empty) )
> > {
> > startdate.Value=System.DBNull.Value;
> > }
> > else
> > {
> > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > }
> > SqlParameter enddate=
> > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > if (txtEndDate.Text.Equals(String.Empty) )
> > {
> > enddate.Value=System.DBNull.Value;
> > }
> > else
> > {
> > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > }
> > SqlParameter status=
> > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > if (txtEndDate.Text.Equals(String.Empty) )
> > {
> > status.Value=System.DBNull.Value;
> > }
> > else
> > {
> > status.Value=ddlStatus.SelectedValue;
> > }
> > }
> > }
> > --
> > pmud
>
>
>

Jul 21 '05 #6
Hi,

I used onsortcommand="DataGrid1_SortCommand"... But it gives me the error:
Server Error in '/ActivationLogs' Application.

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'ASP.Search_aspx' does not contain a
definition for 'SortCommand'

Source Error:

Line 104: <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px;
POSITION: absolute; TOP: 376px"
Line 105: runat="server" Text="Search"></asp:Button>
Line 106: <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px;
POSITION: absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="SortCommand" AutoGenerateColumns="False">
Line 107: <Columns>
Line 108: <asp:BoundColumn DataField="ORDER_NO"
SortExpression="ORDER_NO" ReadOnly="True"
HeaderText="ORDER_NO"></asp:BoundColumn>

My HTML CODE IS::
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 107; LEFT: 264px; POSITION:
absolute; TOP: 24px" runat="server"
Font-Underline="True" Font-Bold="True">VIEW ACTIVATION ORDERS</asp:label>
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 128px;
POSITION: absolute; TOP: 104px; HEIGHT: 24px"
cellSpacing="1" cellPadding="1" width="128" border="0">
<TR>
<TD style="WIDTH: 123px; HEIGHT: 22px">
<asp:linkbutton id="LinkButton1" runat="server"> View All
Orders</asp:linkbutton></TD>
</TR>
</TABLE>
<asp:label id="Label2" style="Z-INDEX: 102; LEFT: 24px; POSITION:
absolute; TOP: 72px" runat="server"
Font-Bold="True" Width="120px">View All Orders::</asp:label>
<TABLE id="Table2" style="Z-INDEX: 103; LEFT: 24px; WIDTH: 608px;
POSITION: absolute; TOP: 160px; HEIGHT: 160px"
cellSpacing="1" cellPadding="1" width="608" border="0">
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label4" runat="server"
Font-Bold="True">Order#</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtOrder" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByOrder"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label5" runat="server"
Font-Bold="True">Status</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:dropdownlist id="ddlStatus" runat="server" Width="152px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Open">Open</asp:ListItem>
<asp:ListItem Value="In Process">In Process</asp:ListItem>
<asp:ListItem Value="Completed">Completed</asp:ListItem>
</asp:dropdownlist></TD>
<TD>
<asp:linkbutton id="lnkByStatus"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px; HEIGHT: 26px">
<asp:label id="Label6" runat="server" Font-Bold="True">Start
Date</asp:label></TD>
<TD style="WIDTH: 146px; HEIGHT: 26px">
<asp:textbox id="txtStartDate" runat="server"></asp:textbox></TD>
<TD style="HEIGHT: 26px"></TD>
<TD style="HEIGHT: 26px">
<asp:label id="Label10" runat="server" Font-Bold="True">End
Date</asp:label></TD>
<TD style="HEIGHT: 26px">
<asp:textbox id="txtEndDate" runat="server"></asp:textbox></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label7" runat="server" Font-Bold="True"
Width="80px">Store</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtStore" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByStore"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label8" runat="server"
Font-Bold="True">Carrier</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtCar" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByCar" runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label9" runat="server" Font-Bold="True">Channel
Manager</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtChlMgr" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByChannelMgr"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px"></TD>
<TD style="WIDTH: 146px"></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<asp:label id="Label3" style="Z-INDEX: 104; LEFT: 24px; POSITION:
absolute; TOP: 136px" runat="server"
Font-Bold="True">View Orders By:</asp:label>
<asp:linkbutton id="lnkByDate" style="Z-INDEX: 105; LEFT: 648px;
POSITION: absolute; TOP: 216px"
runat="server" Width="40px">View</asp:linkbutton>
<asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px; POSITION:
absolute; TOP: 376px"
runat="server" Text="Search"></asp:Button>
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="DataGrid1_SortCommand"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ORDER_NO" SortExpression="ORDER_NO"
ReadOnly="True" HeaderText="ORDER_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" SortExpression="STATUS"
HeaderText="STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_DATE" SortExpression="ORDER_DATE"
HeaderText="ORDER_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CUST_CODE" SortExpression="CUST_CODE"
HeaderText="CUST_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="REF_NO" SortExpression="REF_NO"
HeaderText="REF_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="TERMS" SortExpression="TERMS"
HeaderText="TERMS"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIP_ID" SortExpression="SHIP_ID"
HeaderText="SHIP_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPPED" SortExpression="SHIPPED"
HeaderText="SHIPPED"></asp:BoundColumn>
<asp:BoundColumn DataField="TAXABLE" SortExpression="TAXABLE"
HeaderText="TAXABLE"></asp:BoundColumn>
<asp:BoundColumn DataField="TAX_AMOUNT" SortExpression="TAX_AMOUNT"
HeaderText="TAX_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="EXEMPT" SortExpression="EXEMPT"
HeaderText="EXEMPT"></asp:BoundColumn>
<asp:BoundColumn DataField="DELIV_METH" SortExpression="DELIV_METH"
HeaderText="DELIV_METH"></asp:BoundColumn>
<asp:BoundColumn DataField="MEMOS" SortExpression="MEMOS"
HeaderText="MEMOS"></asp:BoundColumn>
<asp:BoundColumn DataField="WEIGHT" SortExpression="WEIGHT"
HeaderText="WEIGHT"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRCODE" SortExpression="CURRCODE"
HeaderText="CURRCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="INV_AMOUNT" SortExpression="INV_AMOUNT"
HeaderText="INV_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="PAID_AMT" SortExpression="PAID_AMT"
HeaderText="PAID_AMT"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPDATE" SortExpression="SHIPDATE"
HeaderText="SHIPDATE"></asp:BoundColumn>
<asp:BoundColumn DataField="PO" SortExpression="PO"
HeaderText="PO"></asp:BoundColumn>
<asp:BoundColumn DataField="PO_DATE" SortExpression="PO_DATE"
HeaderText="PO_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="BILL_TYPE" SortExpression="BILL_TYPE"
HeaderText="BILL_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_REQUIRED"
SortExpression="PORT_REQUIRED" HeaderText="PORT_REQUIRED"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_ID" SortExpression="PORT_ID"
HeaderText="PORT_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SALES_REP" SortExpression="SALES_REP"
HeaderText="SALES_REP"></asp:BoundColumn>
<asp:BoundColumn DataField="REG_NO" SortExpression="REG_NO"
HeaderText="REG_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_CONFIRMED"
SortExpression="ORDER_CONFIRMED"
HeaderText="ORDER_CONFIRMED"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_ON" SortExpression="CREATED_ON"
HeaderText="CREATED_ON"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_BY" SortExpression="CREATED_BY"
HeaderText="CREATED_BY"></asp:BoundColumn>
<asp:BoundColumn DataField="OPEN_STATUS" SortExpression="OPEN_STATUS"
HeaderText="OPEN_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_STATUS"
SortExpression="APPROVED_STATUS"
HeaderText="APPROVED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_DATE"
SortExpression="APPROVED_DATE" HeaderText="APPROVED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_STATUS"
SortExpression="INPROCESS_STATUS"
HeaderText="INPROCESS_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_DATE"
SortExpression="INPROCESS_DATE" HeaderText="INPROCESS_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_STATUS"
SortExpression="COMPLETED_STATUS"
HeaderText="COMPLETED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_DATE"
SortExpression="COMPLETED_DATE" HeaderText="COMPLETED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_NO"
SortExpression="CREDIT_CARD_NO" HeaderText="CREDIT_CARD_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_TYPE"
SortExpression="CREDIT_CARD_TYPE"
HeaderText="CREDIT_CARD_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_EXPIRY"
SortExpression="CREDIT_CARD_EXPIRY"
HeaderText="CREDIT_CARD_EXPIRY"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
Plz help. It has been almost a week now & this thing isnt working...
"jwkjng" wrote:
Can you put the html for that code-behind as well?

You might want to check if you added the "onsortcommand" field.

The reason i asked for the numberDiv value is that the value might not be
incremented each time you do sorting. I would normally use "ViewState" to
store the order of sorting and flip it each time the sort command is called.
"pmud" wrote:
HI,

Can you plz tell me how to use sorting with the folowing code?
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

Plz help. I am struggling with it since some days now....

Thanks

"jwkjng" wrote:
Can you check the value of numberDiv?
Can you also double-check you SortExpression value?

"pmud" wrote:

> Hi Scott,
>
> I tried that But it didnt work...Any other ideas?
>
> Thanks
>
> "Scott M." wrote:
>
> > Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> > If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> > the end of the sort string.
> >
> >
> > "pmud" <pm**@discussions.microsoft.com> wrote in message
> > news:83**********************************@microsof t.com...
> > > Hi,
> > >
> > > I am using teh following code for sorting the data grid but it doesnt
> > > work.
> > > I have set the auto generate columns to false. & set the sort expression
> > > for
> > > each field as the anme of that field... This grid displayes results based
> > > on
> > > users search..
> > >
> > > public static int numberDiv;
> > > private void Page_Load(object sender, System.EventArgs e)
> > > {
> > > // Put user code to initialize the page here
> > > }
> > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > {
> > > fn();
> > > sqlDataAdapter1.Fill(dsSearch1);
> > >
> > > DataGrid1.DataBind();
> > > }
> > >
> > > private void DataGrid1_SortCommand(object source,
> > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > {
> > > fn();
> > > sqlDataAdapter1.Fill(dsSearch1);
> > > DataView dv = new DataView(dsSearch1.Tables[0]);
> > > if( (numberDiv%2) == 0 )
> > > dv.Sort = e.SortExpression + " " + "ASC";
> > > else
> > > dv.Sort = e.SortExpression + " " + "DESC";
> > > numberDiv++;
> > > DataGrid1.DataSource = dv;
> > > DataGrid1.DataBind();
> > > }
> > > private void fn()
> > > {
> > > sqlSelectCommand1.Parameters.Clear();
> > > SqlParameter order=
> > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > if (txtOrder.Text.Equals(String.Empty))
> > > {
> > > order.Value=System.DBNull.Value;
> > > }
> > > else
> > > {
> > > order.Value=int.Parse(txtOrder.Text);
> > > }
> > > SqlParameter startdate=
> > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > if (txtStartDate.Text.Equals(String.Empty) )
> > > {
> > > startdate.Value=System.DBNull.Value;
> > > }
> > > else
> > > {
> > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > }
> > > SqlParameter enddate=
> > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > if (txtEndDate.Text.Equals(String.Empty) )
> > > {
> > > enddate.Value=System.DBNull.Value;
> > > }
> > > else
> > > {
> > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > }
> > > SqlParameter status=
> > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > if (txtEndDate.Text.Equals(String.Empty) )
> > > {
> > > status.Value=System.DBNull.Value;
> > > }
> > > else
> > > {
> > > status.Value=ddlStatus.SelectedValue;
> > > }
> > > }
> > > }
> > > --
> > > pmud
> >
> >
> >

Jul 21 '05 #7
it says onsortcommand="SortCommand" in your source code.
Please use onsortcommand="DataGrid1_SortCommand"

"pmud" wrote:
Hi,

I used onsortcommand="DataGrid1_SortCommand"... But it gives me the error:
Server Error in '/ActivationLogs' Application.

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'ASP.Search_aspx' does not contain a
definition for 'SortCommand'

Source Error:

Line 104: <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px;
POSITION: absolute; TOP: 376px"
Line 105: runat="server" Text="Search"></asp:Button>
Line 106: <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px;
POSITION: absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="SortCommand" AutoGenerateColumns="False">
Line 107: <Columns>
Line 108: <asp:BoundColumn DataField="ORDER_NO"
SortExpression="ORDER_NO" ReadOnly="True"
HeaderText="ORDER_NO"></asp:BoundColumn>

My HTML CODE IS::
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 107; LEFT: 264px; POSITION:
absolute; TOP: 24px" runat="server"
Font-Underline="True" Font-Bold="True">VIEW ACTIVATION ORDERS</asp:label>
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 128px;
POSITION: absolute; TOP: 104px; HEIGHT: 24px"
cellSpacing="1" cellPadding="1" width="128" border="0">
<TR>
<TD style="WIDTH: 123px; HEIGHT: 22px">
<asp:linkbutton id="LinkButton1" runat="server"> View All
Orders</asp:linkbutton></TD>
</TR>
</TABLE>
<asp:label id="Label2" style="Z-INDEX: 102; LEFT: 24px; POSITION:
absolute; TOP: 72px" runat="server"
Font-Bold="True" Width="120px">View All Orders::</asp:label>
<TABLE id="Table2" style="Z-INDEX: 103; LEFT: 24px; WIDTH: 608px;
POSITION: absolute; TOP: 160px; HEIGHT: 160px"
cellSpacing="1" cellPadding="1" width="608" border="0">
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label4" runat="server"
Font-Bold="True">Order#</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtOrder" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByOrder"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label5" runat="server"
Font-Bold="True">Status</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:dropdownlist id="ddlStatus" runat="server" Width="152px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Open">Open</asp:ListItem>
<asp:ListItem Value="In Process">In Process</asp:ListItem>
<asp:ListItem Value="Completed">Completed</asp:ListItem>
</asp:dropdownlist></TD>
<TD>
<asp:linkbutton id="lnkByStatus"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px; HEIGHT: 26px">
<asp:label id="Label6" runat="server" Font-Bold="True">Start
Date</asp:label></TD>
<TD style="WIDTH: 146px; HEIGHT: 26px">
<asp:textbox id="txtStartDate" runat="server"></asp:textbox></TD>
<TD style="HEIGHT: 26px"></TD>
<TD style="HEIGHT: 26px">
<asp:label id="Label10" runat="server" Font-Bold="True">End
Date</asp:label></TD>
<TD style="HEIGHT: 26px">
<asp:textbox id="txtEndDate" runat="server"></asp:textbox></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label7" runat="server" Font-Bold="True"
Width="80px">Store</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtStore" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByStore"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label8" runat="server"
Font-Bold="True">Carrier</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtCar" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByCar" runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label9" runat="server" Font-Bold="True">Channel
Manager</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtChlMgr" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByChannelMgr"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px"></TD>
<TD style="WIDTH: 146px"></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<asp:label id="Label3" style="Z-INDEX: 104; LEFT: 24px; POSITION:
absolute; TOP: 136px" runat="server"
Font-Bold="True">View Orders By:</asp:label>
<asp:linkbutton id="lnkByDate" style="Z-INDEX: 105; LEFT: 648px;
POSITION: absolute; TOP: 216px"
runat="server" Width="40px">View</asp:linkbutton>
<asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px; POSITION:
absolute; TOP: 376px"
runat="server" Text="Search"></asp:Button>
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="DataGrid1_SortCommand"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ORDER_NO" SortExpression="ORDER_NO"
ReadOnly="True" HeaderText="ORDER_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" SortExpression="STATUS"
HeaderText="STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_DATE" SortExpression="ORDER_DATE"
HeaderText="ORDER_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CUST_CODE" SortExpression="CUST_CODE"
HeaderText="CUST_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="REF_NO" SortExpression="REF_NO"
HeaderText="REF_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="TERMS" SortExpression="TERMS"
HeaderText="TERMS"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIP_ID" SortExpression="SHIP_ID"
HeaderText="SHIP_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPPED" SortExpression="SHIPPED"
HeaderText="SHIPPED"></asp:BoundColumn>
<asp:BoundColumn DataField="TAXABLE" SortExpression="TAXABLE"
HeaderText="TAXABLE"></asp:BoundColumn>
<asp:BoundColumn DataField="TAX_AMOUNT" SortExpression="TAX_AMOUNT"
HeaderText="TAX_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="EXEMPT" SortExpression="EXEMPT"
HeaderText="EXEMPT"></asp:BoundColumn>
<asp:BoundColumn DataField="DELIV_METH" SortExpression="DELIV_METH"
HeaderText="DELIV_METH"></asp:BoundColumn>
<asp:BoundColumn DataField="MEMOS" SortExpression="MEMOS"
HeaderText="MEMOS"></asp:BoundColumn>
<asp:BoundColumn DataField="WEIGHT" SortExpression="WEIGHT"
HeaderText="WEIGHT"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRCODE" SortExpression="CURRCODE"
HeaderText="CURRCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="INV_AMOUNT" SortExpression="INV_AMOUNT"
HeaderText="INV_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="PAID_AMT" SortExpression="PAID_AMT"
HeaderText="PAID_AMT"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPDATE" SortExpression="SHIPDATE"
HeaderText="SHIPDATE"></asp:BoundColumn>
<asp:BoundColumn DataField="PO" SortExpression="PO"
HeaderText="PO"></asp:BoundColumn>
<asp:BoundColumn DataField="PO_DATE" SortExpression="PO_DATE"
HeaderText="PO_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="BILL_TYPE" SortExpression="BILL_TYPE"
HeaderText="BILL_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_REQUIRED"
SortExpression="PORT_REQUIRED" HeaderText="PORT_REQUIRED"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_ID" SortExpression="PORT_ID"
HeaderText="PORT_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SALES_REP" SortExpression="SALES_REP"
HeaderText="SALES_REP"></asp:BoundColumn>
<asp:BoundColumn DataField="REG_NO" SortExpression="REG_NO"
HeaderText="REG_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_CONFIRMED"
SortExpression="ORDER_CONFIRMED"
HeaderText="ORDER_CONFIRMED"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_ON" SortExpression="CREATED_ON"
HeaderText="CREATED_ON"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_BY" SortExpression="CREATED_BY"
HeaderText="CREATED_BY"></asp:BoundColumn>
<asp:BoundColumn DataField="OPEN_STATUS" SortExpression="OPEN_STATUS"
HeaderText="OPEN_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_STATUS"
SortExpression="APPROVED_STATUS"
HeaderText="APPROVED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_DATE"
SortExpression="APPROVED_DATE" HeaderText="APPROVED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_STATUS"
SortExpression="INPROCESS_STATUS"
HeaderText="INPROCESS_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_DATE"
SortExpression="INPROCESS_DATE" HeaderText="INPROCESS_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_STATUS"
SortExpression="COMPLETED_STATUS"
HeaderText="COMPLETED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_DATE"
SortExpression="COMPLETED_DATE" HeaderText="COMPLETED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_NO"
SortExpression="CREDIT_CARD_NO" HeaderText="CREDIT_CARD_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_TYPE"
SortExpression="CREDIT_CARD_TYPE"
HeaderText="CREDIT_CARD_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_EXPIRY"
SortExpression="CREDIT_CARD_EXPIRY"
HeaderText="CREDIT_CARD_EXPIRY"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
Plz help. It has been almost a week now & this thing isnt working...
"jwkjng" wrote:
Can you put the html for that code-behind as well?

You might want to check if you added the "onsortcommand" field.

The reason i asked for the numberDiv value is that the value might not be
incremented each time you do sorting. I would normally use "ViewState" to
store the order of sorting and flip it each time the sort command is called.
"pmud" wrote:
HI,

Can you plz tell me how to use sorting with the folowing code?
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);
DataGrid1.DataBind();
}

private void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

Plz help. I am struggling with it since some days now....

Thanks

"jwkjng" wrote:

> Can you check the value of numberDiv?
> Can you also double-check you SortExpression value?
>
> "pmud" wrote:
>
> > Hi Scott,
> >
> > I tried that But it didnt work...Any other ideas?
> >
> > Thanks
> >
> > "Scott M." wrote:
> >
> > > Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> > > If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> > > the end of the sort string.
> > >
> > >
> > > "pmud" <pm**@discussions.microsoft.com> wrote in message
> > > news:83**********************************@microsof t.com...
> > > > Hi,
> > > >
> > > > I am using teh following code for sorting the data grid but it doesnt
> > > > work.
> > > > I have set the auto generate columns to false. & set the sort expression
> > > > for
> > > > each field as the anme of that field... This grid displayes results based
> > > > on
> > > > users search..
> > > >
> > > > public static int numberDiv;
> > > > private void Page_Load(object sender, System.EventArgs e)
> > > > {
> > > > // Put user code to initialize the page here
> > > > }
> > > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > > {
> > > > fn();
> > > > sqlDataAdapter1.Fill(dsSearch1);
> > > >
> > > > DataGrid1.DataBind();
> > > > }
> > > >
> > > > private void DataGrid1_SortCommand(object source,
> > > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > > {
> > > > fn();
> > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > DataView dv = new DataView(dsSearch1.Tables[0]);
> > > > if( (numberDiv%2) == 0 )
> > > > dv.Sort = e.SortExpression + " " + "ASC";
> > > > else
> > > > dv.Sort = e.SortExpression + " " + "DESC";
> > > > numberDiv++;
> > > > DataGrid1.DataSource = dv;
> > > > DataGrid1.DataBind();
> > > > }
> > > > private void fn()
> > > > {
> > > > sqlSelectCommand1.Parameters.Clear();
> > > > SqlParameter order=
> > > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > > if (txtOrder.Text.Equals(String.Empty))
> > > > {
> > > > order.Value=System.DBNull.Value;
> > > > }
> > > > else
> > > > {
> > > > order.Value=int.Parse(txtOrder.Text);
> > > > }
> > > > SqlParameter startdate=
> > > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > > if (txtStartDate.Text.Equals(String.Empty) )
> > > > {
> > > > startdate.Value=System.DBNull.Value;
> > > > }
> > > > else
> > > > {
> > > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > > }
> > > > SqlParameter enddate=
> > > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > {
> > > > enddate.Value=System.DBNull.Value;
> > > > }
> > > > else
> > > > {
> > > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > > }
> > > > SqlParameter status=
> > > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > {
> > > > status.Value=System.DBNull.Value;
> > > > }
> > > > else
> > > > {
> > > > status.Value=ddlStatus.SelectedValue;
> > > > }
> > > > }
> > > > }
> > > > --
> > > > pmud
> > >
> > >
> > >

Jul 21 '05 #8
Hi, i actually tried to check with both...the error I got was wauth
onsortcommand= DataGrid1_SortCommand ..... Then i changed it to
onSortcommand="SortCommand"...just to check.... So thats not the probelm....

The error was with onsortcommand="DataGrid1_sortCommand" only...

Can u give me some sort code which will work with this?

Thanks

"jwkjng" wrote:
it says onsortcommand="SortCommand" in your source code.
Please use onsortcommand="DataGrid1_SortCommand"

"pmud" wrote:
Hi,

I used onsortcommand="DataGrid1_SortCommand"... But it gives me the error:
Server Error in '/ActivationLogs' Application.

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'ASP.Search_aspx' does not contain a
definition for 'SortCommand'

Source Error:

Line 104: <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px;
POSITION: absolute; TOP: 376px"
Line 105: runat="server" Text="Search"></asp:Button>
Line 106: <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px;
POSITION: absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="SortCommand" AutoGenerateColumns="False">
Line 107: <Columns>
Line 108: <asp:BoundColumn DataField="ORDER_NO"
SortExpression="ORDER_NO" ReadOnly="True"
HeaderText="ORDER_NO"></asp:BoundColumn>

My HTML CODE IS::
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 107; LEFT: 264px; POSITION:
absolute; TOP: 24px" runat="server"
Font-Underline="True" Font-Bold="True">VIEW ACTIVATION ORDERS</asp:label>
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 128px;
POSITION: absolute; TOP: 104px; HEIGHT: 24px"
cellSpacing="1" cellPadding="1" width="128" border="0">
<TR>
<TD style="WIDTH: 123px; HEIGHT: 22px">
<asp:linkbutton id="LinkButton1" runat="server"> View All
Orders</asp:linkbutton></TD>
</TR>
</TABLE>
<asp:label id="Label2" style="Z-INDEX: 102; LEFT: 24px; POSITION:
absolute; TOP: 72px" runat="server"
Font-Bold="True" Width="120px">View All Orders::</asp:label>
<TABLE id="Table2" style="Z-INDEX: 103; LEFT: 24px; WIDTH: 608px;
POSITION: absolute; TOP: 160px; HEIGHT: 160px"
cellSpacing="1" cellPadding="1" width="608" border="0">
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label4" runat="server"
Font-Bold="True">Order#</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtOrder" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByOrder"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label5" runat="server"
Font-Bold="True">Status</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:dropdownlist id="ddlStatus" runat="server" Width="152px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Open">Open</asp:ListItem>
<asp:ListItem Value="In Process">In Process</asp:ListItem>
<asp:ListItem Value="Completed">Completed</asp:ListItem>
</asp:dropdownlist></TD>
<TD>
<asp:linkbutton id="lnkByStatus"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px; HEIGHT: 26px">
<asp:label id="Label6" runat="server" Font-Bold="True">Start
Date</asp:label></TD>
<TD style="WIDTH: 146px; HEIGHT: 26px">
<asp:textbox id="txtStartDate" runat="server"></asp:textbox></TD>
<TD style="HEIGHT: 26px"></TD>
<TD style="HEIGHT: 26px">
<asp:label id="Label10" runat="server" Font-Bold="True">End
Date</asp:label></TD>
<TD style="HEIGHT: 26px">
<asp:textbox id="txtEndDate" runat="server"></asp:textbox></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label7" runat="server" Font-Bold="True"
Width="80px">Store</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtStore" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByStore"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label8" runat="server"
Font-Bold="True">Carrier</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtCar" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByCar" runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label9" runat="server" Font-Bold="True">Channel
Manager</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtChlMgr" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByChannelMgr"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px"></TD>
<TD style="WIDTH: 146px"></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<asp:label id="Label3" style="Z-INDEX: 104; LEFT: 24px; POSITION:
absolute; TOP: 136px" runat="server"
Font-Bold="True">View Orders By:</asp:label>
<asp:linkbutton id="lnkByDate" style="Z-INDEX: 105; LEFT: 648px;
POSITION: absolute; TOP: 216px"
runat="server" Width="40px">View</asp:linkbutton>
<asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px; POSITION:
absolute; TOP: 376px"
runat="server" Text="Search"></asp:Button>
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="DataGrid1_SortCommand"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ORDER_NO" SortExpression="ORDER_NO"
ReadOnly="True" HeaderText="ORDER_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" SortExpression="STATUS"
HeaderText="STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_DATE" SortExpression="ORDER_DATE"
HeaderText="ORDER_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CUST_CODE" SortExpression="CUST_CODE"
HeaderText="CUST_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="REF_NO" SortExpression="REF_NO"
HeaderText="REF_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="TERMS" SortExpression="TERMS"
HeaderText="TERMS"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIP_ID" SortExpression="SHIP_ID"
HeaderText="SHIP_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPPED" SortExpression="SHIPPED"
HeaderText="SHIPPED"></asp:BoundColumn>
<asp:BoundColumn DataField="TAXABLE" SortExpression="TAXABLE"
HeaderText="TAXABLE"></asp:BoundColumn>
<asp:BoundColumn DataField="TAX_AMOUNT" SortExpression="TAX_AMOUNT"
HeaderText="TAX_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="EXEMPT" SortExpression="EXEMPT"
HeaderText="EXEMPT"></asp:BoundColumn>
<asp:BoundColumn DataField="DELIV_METH" SortExpression="DELIV_METH"
HeaderText="DELIV_METH"></asp:BoundColumn>
<asp:BoundColumn DataField="MEMOS" SortExpression="MEMOS"
HeaderText="MEMOS"></asp:BoundColumn>
<asp:BoundColumn DataField="WEIGHT" SortExpression="WEIGHT"
HeaderText="WEIGHT"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRCODE" SortExpression="CURRCODE"
HeaderText="CURRCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="INV_AMOUNT" SortExpression="INV_AMOUNT"
HeaderText="INV_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="PAID_AMT" SortExpression="PAID_AMT"
HeaderText="PAID_AMT"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPDATE" SortExpression="SHIPDATE"
HeaderText="SHIPDATE"></asp:BoundColumn>
<asp:BoundColumn DataField="PO" SortExpression="PO"
HeaderText="PO"></asp:BoundColumn>
<asp:BoundColumn DataField="PO_DATE" SortExpression="PO_DATE"
HeaderText="PO_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="BILL_TYPE" SortExpression="BILL_TYPE"
HeaderText="BILL_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_REQUIRED"
SortExpression="PORT_REQUIRED" HeaderText="PORT_REQUIRED"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_ID" SortExpression="PORT_ID"
HeaderText="PORT_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SALES_REP" SortExpression="SALES_REP"
HeaderText="SALES_REP"></asp:BoundColumn>
<asp:BoundColumn DataField="REG_NO" SortExpression="REG_NO"
HeaderText="REG_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_CONFIRMED"
SortExpression="ORDER_CONFIRMED"
HeaderText="ORDER_CONFIRMED"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_ON" SortExpression="CREATED_ON"
HeaderText="CREATED_ON"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_BY" SortExpression="CREATED_BY"
HeaderText="CREATED_BY"></asp:BoundColumn>
<asp:BoundColumn DataField="OPEN_STATUS" SortExpression="OPEN_STATUS"
HeaderText="OPEN_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_STATUS"
SortExpression="APPROVED_STATUS"
HeaderText="APPROVED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_DATE"
SortExpression="APPROVED_DATE" HeaderText="APPROVED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_STATUS"
SortExpression="INPROCESS_STATUS"
HeaderText="INPROCESS_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_DATE"
SortExpression="INPROCESS_DATE" HeaderText="INPROCESS_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_STATUS"
SortExpression="COMPLETED_STATUS"
HeaderText="COMPLETED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_DATE"
SortExpression="COMPLETED_DATE" HeaderText="COMPLETED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_NO"
SortExpression="CREDIT_CARD_NO" HeaderText="CREDIT_CARD_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_TYPE"
SortExpression="CREDIT_CARD_TYPE"
HeaderText="CREDIT_CARD_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_EXPIRY"
SortExpression="CREDIT_CARD_EXPIRY"
HeaderText="CREDIT_CARD_EXPIRY"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
Plz help. It has been almost a week now & this thing isnt working...
"jwkjng" wrote:
Can you put the html for that code-behind as well?

You might want to check if you added the "onsortcommand" field.

The reason i asked for the numberDiv value is that the value might not be
incremented each time you do sorting. I would normally use "ViewState" to
store the order of sorting and flip it each time the sort command is called.
"pmud" wrote:

> HI,
>
> Can you plz tell me how to use sorting with the folowing code?
> private void btnSearch_Click(object sender, System.EventArgs e)
> {
> fn();
> sqlDataAdapter1.Fill(dsSearch1);
> DataGrid1.DataBind();
> }
>
> private void DataGrid1_SortCommand(object source,
> System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> {
> }
> private void fn()
> {
> sqlSelectCommand1.Parameters.Clear();
> SqlParameter order=
> sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> if (txtOrder.Text.Equals(String.Empty))
> {
> order.Value=System.DBNull.Value;
> }
> else
> {
> order.Value=int.Parse(txtOrder.Text);
> }
> SqlParameter startdate=
> sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> if (txtStartDate.Text.Equals(String.Empty) )
> {
> startdate.Value=System.DBNull.Value;
> }
> else
> {
> startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> }
> SqlParameter enddate=
> sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> if (txtEndDate.Text.Equals(String.Empty) )
> {
> enddate.Value=System.DBNull.Value;
> }
> else
> {
> enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> }
> SqlParameter status=
> sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> if (txtEndDate.Text.Equals(String.Empty) )
> {
> status.Value=System.DBNull.Value;
> }
> else
> {
> status.Value=ddlStatus.SelectedValue;
> }
> }
>
> Plz help. I am struggling with it since some days now....
>
> Thanks
>
> "jwkjng" wrote:
>
> > Can you check the value of numberDiv?
> > Can you also double-check you SortExpression value?
> >
> > "pmud" wrote:
> >
> > > Hi Scott,
> > >
> > > I tried that But it didnt work...Any other ideas?
> > >
> > > Thanks
> > >
> > > "Scott M." wrote:
> > >
> > > > Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> > > > If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> > > > the end of the sort string.
> > > >
> > > >
> > > > "pmud" <pm**@discussions.microsoft.com> wrote in message
> > > > news:83**********************************@microsof t.com...
> > > > > Hi,
> > > > >
> > > > > I am using teh following code for sorting the data grid but it doesnt
> > > > > work.
> > > > > I have set the auto generate columns to false. & set the sort expression
> > > > > for
> > > > > each field as the anme of that field... This grid displayes results based
> > > > > on
> > > > > users search..
> > > > >
> > > > > public static int numberDiv;
> > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > {
> > > > > // Put user code to initialize the page here
> > > > > }
> > > > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > > > {
> > > > > fn();
> > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > >
> > > > > DataGrid1.DataBind();
> > > > > }
> > > > >
> > > > > private void DataGrid1_SortCommand(object source,
> > > > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > > > {
> > > > > fn();
> > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > DataView dv = new DataView(dsSearch1.Tables[0]);
> > > > > if( (numberDiv%2) == 0 )
> > > > > dv.Sort = e.SortExpression + " " + "ASC";
> > > > > else
> > > > > dv.Sort = e.SortExpression + " " + "DESC";
> > > > > numberDiv++;
> > > > > DataGrid1.DataSource = dv;
> > > > > DataGrid1.DataBind();
> > > > > }
> > > > > private void fn()
> > > > > {
> > > > > sqlSelectCommand1.Parameters.Clear();
> > > > > SqlParameter order=
> > > > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > > > if (txtOrder.Text.Equals(String.Empty))
> > > > > {
> > > > > order.Value=System.DBNull.Value;
> > > > > }
> > > > > else
> > > > > {
> > > > > order.Value=int.Parse(txtOrder.Text);
> > > > > }
> > > > > SqlParameter startdate=
> > > > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > > > if (txtStartDate.Text.Equals(String.Empty) )
> > > > > {
> > > > > startdate.Value=System.DBNull.Value;
> > > > > }
> > > > > else
> > > > > {
> > > > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > > > }
> > > > > SqlParameter enddate=
> > > > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > {
> > > > > enddate.Value=System.DBNull.Value;
> > > > > }
> > > > > else
> > > > > {
> > > > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > > > }
> > > > > SqlParameter status=
> > > > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > {
> > > > > status.Value=System.DBNull.Value;
> > > > > }
> > > > > else
> > > > > {
> > > > > status.Value=ddlStatus.SelectedValue;
> > > > > }
> > > > > }
> > > > > }
> > > > > --
> > > > > pmud
> > > >
> > > >
> > > >

Jul 21 '05 #9
Change in your code behind
"private" void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)

to
"protected"

That's why it's not finding it.

By the way, you only need to do this if you didn't hard-code the event in
the initializecomponet method.
"pmud" wrote:
Hi, i actually tried to check with both...the error I got was wauth
onsortcommand= DataGrid1_SortCommand ..... Then i changed it to
onSortcommand="SortCommand"...just to check.... So thats not the probelm....

The error was with onsortcommand="DataGrid1_sortCommand" only...

Can u give me some sort code which will work with this?

Thanks

"jwkjng" wrote:
it says onsortcommand="SortCommand" in your source code.
Please use onsortcommand="DataGrid1_SortCommand"

"pmud" wrote:
Hi,

I used onsortcommand="DataGrid1_SortCommand"... But it gives me the error:
Server Error in '/ActivationLogs' Application.

Compilation Error
Description: An error occurred during the compilation of a resource required
to service this request. Please review the following specific error details
and modify your source code appropriately.

Compiler Error Message: CS0117: 'ASP.Search_aspx' does not contain a
definition for 'SortCommand'

Source Error:

Line 104: <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px;
POSITION: absolute; TOP: 376px"
Line 105: runat="server" Text="Search"></asp:Button>
Line 106: <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px;
POSITION: absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="SortCommand" AutoGenerateColumns="False">
Line 107: <Columns>
Line 108: <asp:BoundColumn DataField="ORDER_NO"
SortExpression="ORDER_NO" ReadOnly="True"
HeaderText="ORDER_NO"></asp:BoundColumn>

My HTML CODE IS::
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:label id="Label1" style="Z-INDEX: 107; LEFT: 264px; POSITION:
absolute; TOP: 24px" runat="server"
Font-Underline="True" Font-Bold="True">VIEW ACTIVATION ORDERS</asp:label>
<TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 128px;
POSITION: absolute; TOP: 104px; HEIGHT: 24px"
cellSpacing="1" cellPadding="1" width="128" border="0">
<TR>
<TD style="WIDTH: 123px; HEIGHT: 22px">
<asp:linkbutton id="LinkButton1" runat="server"> View All
Orders</asp:linkbutton></TD>
</TR>
</TABLE>
<asp:label id="Label2" style="Z-INDEX: 102; LEFT: 24px; POSITION:
absolute; TOP: 72px" runat="server"
Font-Bold="True" Width="120px">View All Orders::</asp:label>
<TABLE id="Table2" style="Z-INDEX: 103; LEFT: 24px; WIDTH: 608px;
POSITION: absolute; TOP: 160px; HEIGHT: 160px"
cellSpacing="1" cellPadding="1" width="608" border="0">
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label4" runat="server"
Font-Bold="True">Order#</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtOrder" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByOrder"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label5" runat="server"
Font-Bold="True">Status</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:dropdownlist id="ddlStatus" runat="server" Width="152px">
<asp:ListItem></asp:ListItem>
<asp:ListItem Value="Open">Open</asp:ListItem>
<asp:ListItem Value="In Process">In Process</asp:ListItem>
<asp:ListItem Value="Completed">Completed</asp:ListItem>
</asp:dropdownlist></TD>
<TD>
<asp:linkbutton id="lnkByStatus"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px; HEIGHT: 26px">
<asp:label id="Label6" runat="server" Font-Bold="True">Start
Date</asp:label></TD>
<TD style="WIDTH: 146px; HEIGHT: 26px">
<asp:textbox id="txtStartDate" runat="server"></asp:textbox></TD>
<TD style="HEIGHT: 26px"></TD>
<TD style="HEIGHT: 26px">
<asp:label id="Label10" runat="server" Font-Bold="True">End
Date</asp:label></TD>
<TD style="HEIGHT: 26px">
<asp:textbox id="txtEndDate" runat="server"></asp:textbox></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label7" runat="server" Font-Bold="True"
Width="80px">Store</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtStore" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByStore"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label8" runat="server"
Font-Bold="True">Carrier</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtCar" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByCar" runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px">
<asp:label id="Label9" runat="server" Font-Bold="True">Channel
Manager</asp:label></TD>
<TD style="WIDTH: 146px">
<asp:textbox id="txtChlMgr" runat="server"></asp:textbox></TD>
<TD>
<asp:linkbutton id="lnkByChannelMgr"
runat="server">View</asp:linkbutton></TD>
<TD></TD>
<TD></TD>
</TR>
<TR>
<TD style="WIDTH: 130px"></TD>
<TD style="WIDTH: 146px"></TD>
<TD></TD>
<TD></TD>
<TD></TD>
</TR>
</TABLE>
<asp:label id="Label3" style="Z-INDEX: 104; LEFT: 24px; POSITION:
absolute; TOP: 136px" runat="server"
Font-Bold="True">View Orders By:</asp:label>
<asp:linkbutton id="lnkByDate" style="Z-INDEX: 105; LEFT: 648px;
POSITION: absolute; TOP: 216px"
runat="server" Width="40px">View</asp:linkbutton>
<asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px; POSITION:
absolute; TOP: 376px"
runat="server" Text="Search"></asp:Button>
<asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px; POSITION:
absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
AllowSorting="True" OnSortCommand="DataGrid1_SortCommand"
AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn DataField="ORDER_NO" SortExpression="ORDER_NO"
ReadOnly="True" HeaderText="ORDER_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="STATUS" SortExpression="STATUS"
HeaderText="STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_DATE" SortExpression="ORDER_DATE"
HeaderText="ORDER_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CUST_CODE" SortExpression="CUST_CODE"
HeaderText="CUST_CODE"></asp:BoundColumn>
<asp:BoundColumn DataField="REF_NO" SortExpression="REF_NO"
HeaderText="REF_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="TERMS" SortExpression="TERMS"
HeaderText="TERMS"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIP_ID" SortExpression="SHIP_ID"
HeaderText="SHIP_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPPED" SortExpression="SHIPPED"
HeaderText="SHIPPED"></asp:BoundColumn>
<asp:BoundColumn DataField="TAXABLE" SortExpression="TAXABLE"
HeaderText="TAXABLE"></asp:BoundColumn>
<asp:BoundColumn DataField="TAX_AMOUNT" SortExpression="TAX_AMOUNT"
HeaderText="TAX_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="EXEMPT" SortExpression="EXEMPT"
HeaderText="EXEMPT"></asp:BoundColumn>
<asp:BoundColumn DataField="DELIV_METH" SortExpression="DELIV_METH"
HeaderText="DELIV_METH"></asp:BoundColumn>
<asp:BoundColumn DataField="MEMOS" SortExpression="MEMOS"
HeaderText="MEMOS"></asp:BoundColumn>
<asp:BoundColumn DataField="WEIGHT" SortExpression="WEIGHT"
HeaderText="WEIGHT"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRCODE" SortExpression="CURRCODE"
HeaderText="CURRCODE"></asp:BoundColumn>
<asp:BoundColumn DataField="INV_AMOUNT" SortExpression="INV_AMOUNT"
HeaderText="INV_AMOUNT"></asp:BoundColumn>
<asp:BoundColumn DataField="PAID_AMT" SortExpression="PAID_AMT"
HeaderText="PAID_AMT"></asp:BoundColumn>
<asp:BoundColumn DataField="SHIPDATE" SortExpression="SHIPDATE"
HeaderText="SHIPDATE"></asp:BoundColumn>
<asp:BoundColumn DataField="PO" SortExpression="PO"
HeaderText="PO"></asp:BoundColumn>
<asp:BoundColumn DataField="PO_DATE" SortExpression="PO_DATE"
HeaderText="PO_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="BILL_TYPE" SortExpression="BILL_TYPE"
HeaderText="BILL_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_REQUIRED"
SortExpression="PORT_REQUIRED" HeaderText="PORT_REQUIRED"></asp:BoundColumn>
<asp:BoundColumn DataField="PORT_ID" SortExpression="PORT_ID"
HeaderText="PORT_ID"></asp:BoundColumn>
<asp:BoundColumn DataField="SALES_REP" SortExpression="SALES_REP"
HeaderText="SALES_REP"></asp:BoundColumn>
<asp:BoundColumn DataField="REG_NO" SortExpression="REG_NO"
HeaderText="REG_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="ORDER_CONFIRMED"
SortExpression="ORDER_CONFIRMED"
HeaderText="ORDER_CONFIRMED"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_ON" SortExpression="CREATED_ON"
HeaderText="CREATED_ON"></asp:BoundColumn>
<asp:BoundColumn DataField="CREATED_BY" SortExpression="CREATED_BY"
HeaderText="CREATED_BY"></asp:BoundColumn>
<asp:BoundColumn DataField="OPEN_STATUS" SortExpression="OPEN_STATUS"
HeaderText="OPEN_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_STATUS"
SortExpression="APPROVED_STATUS"
HeaderText="APPROVED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="APPROVED_DATE"
SortExpression="APPROVED_DATE" HeaderText="APPROVED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_STATUS"
SortExpression="INPROCESS_STATUS"
HeaderText="INPROCESS_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="INPROCESS_DATE"
SortExpression="INPROCESS_DATE" HeaderText="INPROCESS_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_STATUS"
SortExpression="COMPLETED_STATUS"
HeaderText="COMPLETED_STATUS"></asp:BoundColumn>
<asp:BoundColumn DataField="COMPLETED_DATE"
SortExpression="COMPLETED_DATE" HeaderText="COMPLETED_DATE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_NO"
SortExpression="CREDIT_CARD_NO" HeaderText="CREDIT_CARD_NO"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_TYPE"
SortExpression="CREDIT_CARD_TYPE"
HeaderText="CREDIT_CARD_TYPE"></asp:BoundColumn>
<asp:BoundColumn DataField="CREDIT_CARD_EXPIRY"
SortExpression="CREDIT_CARD_EXPIRY"
HeaderText="CREDIT_CARD_EXPIRY"></asp:BoundColumn>
</Columns>
</asp:DataGrid>
</form>
</body>
</HTML>
Plz help. It has been almost a week now & this thing isnt working...
"jwkjng" wrote:

> Can you put the html for that code-behind as well?
>
> You might want to check if you added the "onsortcommand" field.
>
> The reason i asked for the numberDiv value is that the value might not be
> incremented each time you do sorting. I would normally use "ViewState" to
> store the order of sorting and flip it each time the sort command is called.
>
>
> "pmud" wrote:
>
> > HI,
> >
> > Can you plz tell me how to use sorting with the folowing code?
> > private void btnSearch_Click(object sender, System.EventArgs e)
> > {
> > fn();
> > sqlDataAdapter1.Fill(dsSearch1);
> > DataGrid1.DataBind();
> > }
> >
> > private void DataGrid1_SortCommand(object source,
> > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > {
> > }
> > private void fn()
> > {
> > sqlSelectCommand1.Parameters.Clear();
> > SqlParameter order=
> > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > if (txtOrder.Text.Equals(String.Empty))
> > {
> > order.Value=System.DBNull.Value;
> > }
> > else
> > {
> > order.Value=int.Parse(txtOrder.Text);
> > }
> > SqlParameter startdate=
> > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > if (txtStartDate.Text.Equals(String.Empty) )
> > {
> > startdate.Value=System.DBNull.Value;
> > }
> > else
> > {
> > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > }
> > SqlParameter enddate=
> > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > if (txtEndDate.Text.Equals(String.Empty) )
> > {
> > enddate.Value=System.DBNull.Value;
> > }
> > else
> > {
> > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > }
> > SqlParameter status=
> > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > if (txtEndDate.Text.Equals(String.Empty) )
> > {
> > status.Value=System.DBNull.Value;
> > }
> > else
> > {
> > status.Value=ddlStatus.SelectedValue;
> > }
> > }
> >
> > Plz help. I am struggling with it since some days now....
> >
> > Thanks
> >
> > "jwkjng" wrote:
> >
> > > Can you check the value of numberDiv?
> > > Can you also double-check you SortExpression value?
> > >
> > > "pmud" wrote:
> > >
> > > > Hi Scott,
> > > >
> > > > I tried that But it didnt work...Any other ideas?
> > > >
> > > > Thanks
> > > >
> > > > "Scott M." wrote:
> > > >
> > > > > Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> > > > > If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> > > > > the end of the sort string.
> > > > >
> > > > >
> > > > > "pmud" <pm**@discussions.microsoft.com> wrote in message
> > > > > news:83**********************************@microsof t.com...
> > > > > > Hi,
> > > > > >
> > > > > > I am using teh following code for sorting the data grid but it doesnt
> > > > > > work.
> > > > > > I have set the auto generate columns to false. & set the sort expression
> > > > > > for
> > > > > > each field as the anme of that field... This grid displayes results based
> > > > > > on
> > > > > > users search..
> > > > > >
> > > > > > public static int numberDiv;
> > > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > > {
> > > > > > // Put user code to initialize the page here
> > > > > > }
> > > > > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > > > > {
> > > > > > fn();
> > > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > >
> > > > > > DataGrid1.DataBind();
> > > > > > }
> > > > > >
> > > > > > private void DataGrid1_SortCommand(object source,
> > > > > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > > > > {
> > > > > > fn();
> > > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > > DataView dv = new DataView(dsSearch1.Tables[0]);
> > > > > > if( (numberDiv%2) == 0 )
> > > > > > dv.Sort = e.SortExpression + " " + "ASC";
> > > > > > else
> > > > > > dv.Sort = e.SortExpression + " " + "DESC";
> > > > > > numberDiv++;
> > > > > > DataGrid1.DataSource = dv;
> > > > > > DataGrid1.DataBind();
> > > > > > }
> > > > > > private void fn()
> > > > > > {
> > > > > > sqlSelectCommand1.Parameters.Clear();
> > > > > > SqlParameter order=
> > > > > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > > > > if (txtOrder.Text.Equals(String.Empty))
> > > > > > {
> > > > > > order.Value=System.DBNull.Value;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > order.Value=int.Parse(txtOrder.Text);
> > > > > > }
> > > > > > SqlParameter startdate=
> > > > > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > > > > if (txtStartDate.Text.Equals(String.Empty) )
> > > > > > {
> > > > > > startdate.Value=System.DBNull.Value;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > > > > }
> > > > > > SqlParameter enddate=
> > > > > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > {
> > > > > > enddate.Value=System.DBNull.Value;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > > > > }
> > > > > > SqlParameter status=
> > > > > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > {
> > > > > > status.Value=System.DBNull.Value;
> > > > > > }
> > > > > > else
> > > > > > {
> > > > > > status.Value=ddlStatus.SelectedValue;
> > > > > > }
> > > > > > }
> > > > > > }
> > > > > > --
> > > > > > pmud
> > > > >
> > > > >
> > > > >

Jul 21 '05 #10
hi,

I used the following code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
if (ViewState["sortorder"] == null)
{
ViewState["sortorder"] = "ASC";
}
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

protected void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
//Response.Write(numberDiv.ToString());
fn();

sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
dv.Sort = e.SortExpression + " " + ViewState["sortorder"].ToString();
//toggle sortorder
if (ViewState["sortorder"] == "ASC")
ViewState["sortorder"] = "DESC";
else
ViewState["sortorder"] = "ASC";
DataGrid1.DataSource = dv;
DataGrid1.DataBind();

}
private void fn()
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

It is still not sorting... I think there is some error in it...I cant find
out... Plz help... Also the build succeeds but it shows a blue mark below the
line..............................if (ViewState["sortorder"] ==
"ASC")..........meaning that it is error but cannot understand whats wrong
here.

Plz help...

Thanks

"jwkjng" wrote:
Yea, like i said before, I would normally use ViewState.
But, that means that that event is being fired, and it doesn't do any sorting?

as for using ViewState, do something like this.

in Page_Load
if (!Page.IsPostback)
if (ViewState["sortorder"] == null)
ViewState["sortorder"] = "ASC";
then in your sortcommand,
dv.Sort = e.SortExpression + " " + ViewState["sortorder"].ToString();
//toggle sortorder
if (ViewState["sortorder"] == "ASC")
ViewState["sortorder"] = "DESC";
else
ViewState["sortorder"] = "ASC";

OK.. and did you try changing the name of your form? I know it sounds
absurd, but just give it a try
"pmud" wrote:
Hi,

You know what...its so strange...i added the response.write & the values the
numberDiv is taking are... 1 , 23, 45, 67, 89........

when i clicked the other column header it took the value 1011....

when i clickd the 3rd colimn heading, i got the value as 1213.....

That is soooo strange.... Can it be bcoz my data grid had more than 30
columns???

"jwkjng" wrote:
Can you add "Response.Write(numberDiv.ToString());" in the
DataGrid1_SortCommand event and see if it gets fired at all and it does get
incremented each time the header is clicked?

Also try changing the name of the form from "form1" to something else and
try it.
"pmud" wrote:

> Hi,
>
> I changed it to protected but with no luck..when header is clicked ,it
> doesnt sort, it still shows the same thing..... I didnt hard code the Sort
> event... I went to events section of the properties for data grid & double
> clicked the sort event...thst how the handler was created...
>
>
> "jwkjng" wrote:
>
> > Change in your code behind
> > "private" void DataGrid1_SortCommand(object source,
> > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> >
> > to
> > "protected"
> >
> > That's why it's not finding it.
> >
> > By the way, you only need to do this if you didn't hard-code the event in
> > the initializecomponet method.
> >
> >
> > "pmud" wrote:
> >
> > > Hi, i actually tried to check with both...the error I got was wauth
> > > onsortcommand= DataGrid1_SortCommand ..... Then i changed it to
> > > onSortcommand="SortCommand"...just to check.... So thats not the probelm....
> > >
> > > The error was with onsortcommand="DataGrid1_sortCommand" only...
> > >
> > > Can u give me some sort code which will work with this?
> > >
> > > Thanks
> > >
> > > "jwkjng" wrote:
> > >
> > > > it says onsortcommand="SortCommand" in your source code.
> > > > Please use onsortcommand="DataGrid1_SortCommand"
> > > >
> > > > "pmud" wrote:
> > > >
> > > > > Hi,
> > > > >
> > > > > I used onsortcommand="DataGrid1_SortCommand"... But it gives me the error:
> > > > > Server Error in '/ActivationLogs' Application.
> > > > >
> > > > > Compilation Error
> > > > > Description: An error occurred during the compilation of a resource required
> > > > > to service this request. Please review the following specific error details
> > > > > and modify your source code appropriately.
> > > > >
> > > > > Compiler Error Message: CS0117: 'ASP.Search_aspx' does not contain a
> > > > > definition for 'SortCommand'
> > > > >
> > > > > Source Error:
> > > > >
> > > > > Line 104: <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px;
> > > > > POSITION: absolute; TOP: 376px"
> > > > > Line 105: runat="server" Text="Search"></asp:Button>
> > > > > Line 106: <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px;
> > > > > POSITION: absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
> > > > > DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
> > > > > AllowSorting="True" OnSortCommand="SortCommand" AutoGenerateColumns="False">
> > > > > Line 107: <Columns>
> > > > > Line 108: <asp:BoundColumn DataField="ORDER_NO"
> > > > > SortExpression="ORDER_NO" ReadOnly="True"
> > > > > HeaderText="ORDER_NO"></asp:BoundColumn>
> > > > >
> > > > > My HTML CODE IS::
> > > > > <body MS_POSITIONING="GridLayout">
> > > > > <form id="Form1" method="post" runat="server">
> > > > > <asp:label id="Label1" style="Z-INDEX: 107; LEFT: 264px; POSITION:
> > > > > absolute; TOP: 24px" runat="server"
> > > > > Font-Underline="True" Font-Bold="True">VIEW ACTIVATION ORDERS</asp:label>
> > > > > <TABLE id="Table1" style="Z-INDEX: 101; LEFT: 32px; WIDTH: 128px;
> > > > > POSITION: absolute; TOP: 104px; HEIGHT: 24px"
> > > > > cellSpacing="1" cellPadding="1" width="128" border="0">
> > > > > <TR>
> > > > > <TD style="WIDTH: 123px; HEIGHT: 22px">
> > > > > <asp:linkbutton id="LinkButton1" runat="server"> View All
> > > > > Orders</asp:linkbutton></TD>
> > > > > </TR>
> > > > > </TABLE>
> > > > > <asp:label id="Label2" style="Z-INDEX: 102; LEFT: 24px; POSITION:
> > > > > absolute; TOP: 72px" runat="server"
> > > > > Font-Bold="True" Width="120px">View All Orders::</asp:label>
> > > > > <TABLE id="Table2" style="Z-INDEX: 103; LEFT: 24px; WIDTH: 608px;
> > > > > POSITION: absolute; TOP: 160px; HEIGHT: 160px"
> > > > > cellSpacing="1" cellPadding="1" width="608" border="0">
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px">
> > > > > <asp:label id="Label4" runat="server"
> > > > > Font-Bold="True">Order#</asp:label></TD>
> > > > > <TD style="WIDTH: 146px">
> > > > > <asp:textbox id="txtOrder" runat="server"></asp:textbox></TD>
> > > > > <TD>
> > > > > <asp:linkbutton id="lnkByOrder"
> > > > > runat="server">View</asp:linkbutton></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px">
> > > > > <asp:label id="Label5" runat="server"
> > > > > Font-Bold="True">Status</asp:label></TD>
> > > > > <TD style="WIDTH: 146px">
> > > > > <asp:dropdownlist id="ddlStatus" runat="server" Width="152px">
> > > > > <asp:ListItem></asp:ListItem>
> > > > > <asp:ListItem Value="Open">Open</asp:ListItem>
> > > > > <asp:ListItem Value="In Process">In Process</asp:ListItem>
> > > > > <asp:ListItem Value="Completed">Completed</asp:ListItem>
> > > > > </asp:dropdownlist></TD>
> > > > > <TD>
> > > > > <asp:linkbutton id="lnkByStatus"
> > > > > runat="server">View</asp:linkbutton></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px; HEIGHT: 26px">
> > > > > <asp:label id="Label6" runat="server" Font-Bold="True">Start
> > > > > Date</asp:label></TD>
> > > > > <TD style="WIDTH: 146px; HEIGHT: 26px">
> > > > > <asp:textbox id="txtStartDate" runat="server"></asp:textbox></TD>
> > > > > <TD style="HEIGHT: 26px"></TD>
> > > > > <TD style="HEIGHT: 26px">
> > > > > <asp:label id="Label10" runat="server" Font-Bold="True">End
> > > > > Date</asp:label></TD>
> > > > > <TD style="HEIGHT: 26px">
> > > > > <asp:textbox id="txtEndDate" runat="server"></asp:textbox></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px">
> > > > > <asp:label id="Label7" runat="server" Font-Bold="True"
> > > > > Width="80px">Store</asp:label></TD>
> > > > > <TD style="WIDTH: 146px">
> > > > > <asp:textbox id="txtStore" runat="server"></asp:textbox></TD>
> > > > > <TD>
> > > > > <asp:linkbutton id="lnkByStore"
> > > > > runat="server">View</asp:linkbutton></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px">
> > > > > <asp:label id="Label8" runat="server"
> > > > > Font-Bold="True">Carrier</asp:label></TD>
> > > > > <TD style="WIDTH: 146px">
> > > > > <asp:textbox id="txtCar" runat="server"></asp:textbox></TD>
> > > > > <TD>
> > > > > <asp:linkbutton id="lnkByCar" runat="server">View</asp:linkbutton></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px">
> > > > > <asp:label id="Label9" runat="server" Font-Bold="True">Channel
> > > > > Manager</asp:label></TD>
> > > > > <TD style="WIDTH: 146px">
> > > > > <asp:textbox id="txtChlMgr" runat="server"></asp:textbox></TD>
> > > > > <TD>
> > > > > <asp:linkbutton id="lnkByChannelMgr"
> > > > > runat="server">View</asp:linkbutton></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > <TR>
> > > > > <TD style="WIDTH: 130px"></TD>
> > > > > <TD style="WIDTH: 146px"></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > <TD></TD>
> > > > > </TR>
> > > > > </TABLE>
> > > > > <asp:label id="Label3" style="Z-INDEX: 104; LEFT: 24px; POSITION:
> > > > > absolute; TOP: 136px" runat="server"
> > > > > Font-Bold="True">View Orders By:</asp:label>
> > > > > <asp:linkbutton id="lnkByDate" style="Z-INDEX: 105; LEFT: 648px;
> > > > > POSITION: absolute; TOP: 216px"
> > > > > runat="server" Width="40px">View</asp:linkbutton>
> > > > > <asp:Button id="btnSearch" style="Z-INDEX: 106; LEFT: 320px; POSITION:
> > > > > absolute; TOP: 376px"
> > > > > runat="server" Text="Search"></asp:Button>
> > > > > <asp:DataGrid id=DataGrid1 style="Z-INDEX: 108; LEFT: 16px; POSITION:
> > > > > absolute; TOP: 408px" runat="server" DataSource="<%# dsSearch1 %>"
> > > > > DataMember="usp_MasterBrowser_SearchSProcedure" DataKeyField="ORDER_NO"
> > > > > AllowSorting="True" OnSortCommand="DataGrid1_SortCommand"
> > > > > AutoGenerateColumns="False">
> > > > > <Columns>
> > > > > <asp:BoundColumn DataField="ORDER_NO" SortExpression="ORDER_NO"
> > > > > ReadOnly="True" HeaderText="ORDER_NO"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="STATUS" SortExpression="STATUS"
> > > > > HeaderText="STATUS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="ORDER_DATE" SortExpression="ORDER_DATE"
> > > > > HeaderText="ORDER_DATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CUST_CODE" SortExpression="CUST_CODE"
> > > > > HeaderText="CUST_CODE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="REF_NO" SortExpression="REF_NO"
> > > > > HeaderText="REF_NO"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="TERMS" SortExpression="TERMS"
> > > > > HeaderText="TERMS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="SHIP_ID" SortExpression="SHIP_ID"
> > > > > HeaderText="SHIP_ID"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="SHIPPED" SortExpression="SHIPPED"
> > > > > HeaderText="SHIPPED"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="TAXABLE" SortExpression="TAXABLE"
> > > > > HeaderText="TAXABLE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="TAX_AMOUNT" SortExpression="TAX_AMOUNT"
> > > > > HeaderText="TAX_AMOUNT"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="EXEMPT" SortExpression="EXEMPT"
> > > > > HeaderText="EXEMPT"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="DELIV_METH" SortExpression="DELIV_METH"
> > > > > HeaderText="DELIV_METH"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="MEMOS" SortExpression="MEMOS"
> > > > > HeaderText="MEMOS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="WEIGHT" SortExpression="WEIGHT"
> > > > > HeaderText="WEIGHT"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CURRCODE" SortExpression="CURRCODE"
> > > > > HeaderText="CURRCODE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="INV_AMOUNT" SortExpression="INV_AMOUNT"
> > > > > HeaderText="INV_AMOUNT"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="PAID_AMT" SortExpression="PAID_AMT"
> > > > > HeaderText="PAID_AMT"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="SHIPDATE" SortExpression="SHIPDATE"
> > > > > HeaderText="SHIPDATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="PO" SortExpression="PO"
> > > > > HeaderText="PO"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="PO_DATE" SortExpression="PO_DATE"
> > > > > HeaderText="PO_DATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="BILL_TYPE" SortExpression="BILL_TYPE"
> > > > > HeaderText="BILL_TYPE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="PORT_REQUIRED"
> > > > > SortExpression="PORT_REQUIRED" HeaderText="PORT_REQUIRED"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="PORT_ID" SortExpression="PORT_ID"
> > > > > HeaderText="PORT_ID"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="SALES_REP" SortExpression="SALES_REP"
> > > > > HeaderText="SALES_REP"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="REG_NO" SortExpression="REG_NO"
> > > > > HeaderText="REG_NO"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="ORDER_CONFIRMED"
> > > > > SortExpression="ORDER_CONFIRMED"
> > > > > HeaderText="ORDER_CONFIRMED"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CREATED_ON" SortExpression="CREATED_ON"
> > > > > HeaderText="CREATED_ON"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CREATED_BY" SortExpression="CREATED_BY"
> > > > > HeaderText="CREATED_BY"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="OPEN_STATUS" SortExpression="OPEN_STATUS"
> > > > > HeaderText="OPEN_STATUS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="APPROVED_STATUS"
> > > > > SortExpression="APPROVED_STATUS"
> > > > > HeaderText="APPROVED_STATUS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="APPROVED_DATE"
> > > > > SortExpression="APPROVED_DATE" HeaderText="APPROVED_DATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="INPROCESS_STATUS"
> > > > > SortExpression="INPROCESS_STATUS"
> > > > > HeaderText="INPROCESS_STATUS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="INPROCESS_DATE"
> > > > > SortExpression="INPROCESS_DATE" HeaderText="INPROCESS_DATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="COMPLETED_STATUS"
> > > > > SortExpression="COMPLETED_STATUS"
> > > > > HeaderText="COMPLETED_STATUS"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="COMPLETED_DATE"
> > > > > SortExpression="COMPLETED_DATE" HeaderText="COMPLETED_DATE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CREDIT_CARD_NO"
> > > > > SortExpression="CREDIT_CARD_NO" HeaderText="CREDIT_CARD_NO"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CREDIT_CARD_TYPE"
> > > > > SortExpression="CREDIT_CARD_TYPE"
> > > > > HeaderText="CREDIT_CARD_TYPE"></asp:BoundColumn>
> > > > > <asp:BoundColumn DataField="CREDIT_CARD_EXPIRY"
> > > > > SortExpression="CREDIT_CARD_EXPIRY"
> > > > > HeaderText="CREDIT_CARD_EXPIRY"></asp:BoundColumn>
> > > > > </Columns>
> > > > > </asp:DataGrid>
> > > > > </form>
> > > > > </body>
> > > > > </HTML>
> > > > > Plz help. It has been almost a week now & this thing isnt working...
> > > > > "jwkjng" wrote:
> > > > >
> > > > > > Can you put the html for that code-behind as well?
> > > > > >
> > > > > > You might want to check if you added the "onsortcommand" field.
> > > > > >
> > > > > > The reason i asked for the numberDiv value is that the value might not be
> > > > > > incremented each time you do sorting. I would normally use "ViewState" to
> > > > > > store the order of sorting and flip it each time the sort command is called.
> > > > > >
> > > > > >
> > > > > > "pmud" wrote:
> > > > > >
> > > > > > > HI,
> > > > > > >
> > > > > > > Can you plz tell me how to use sorting with the folowing code?
> > > > > > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > > > > > {
> > > > > > > fn();
> > > > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > > > DataGrid1.DataBind();
> > > > > > > }
> > > > > > >
> > > > > > > private void DataGrid1_SortCommand(object source,
> > > > > > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > > > > > {
> > > > > > > }
> > > > > > > private void fn()
> > > > > > > {
> > > > > > > sqlSelectCommand1.Parameters.Clear();
> > > > > > > SqlParameter order=
> > > > > > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > > > > > if (txtOrder.Text.Equals(String.Empty))
> > > > > > > {
> > > > > > > order.Value=System.DBNull.Value;
> > > > > > > }
> > > > > > > else
> > > > > > > {
> > > > > > > order.Value=int.Parse(txtOrder.Text);
> > > > > > > }
> > > > > > > SqlParameter startdate=
> > > > > > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > > > > > if (txtStartDate.Text.Equals(String.Empty) )
> > > > > > > {
> > > > > > > startdate.Value=System.DBNull.Value;
> > > > > > > }
> > > > > > > else
> > > > > > > {
> > > > > > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > > > > > }
> > > > > > > SqlParameter enddate=
> > > > > > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > > {
> > > > > > > enddate.Value=System.DBNull.Value;
> > > > > > > }
> > > > > > > else
> > > > > > > {
> > > > > > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > > > > > }
> > > > > > > SqlParameter status=
> > > > > > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > > {
> > > > > > > status.Value=System.DBNull.Value;
> > > > > > > }
> > > > > > > else
> > > > > > > {
> > > > > > > status.Value=ddlStatus.SelectedValue;
> > > > > > > }
> > > > > > > }
> > > > > > >
> > > > > > > Plz help. I am struggling with it since some days now....
> > > > > > >
> > > > > > > Thanks
> > > > > > >
> > > > > > > "jwkjng" wrote:
> > > > > > >
> > > > > > > > Can you check the value of numberDiv?
> > > > > > > > Can you also double-check you SortExpression value?
> > > > > > > >
> > > > > > > > "pmud" wrote:
> > > > > > > >
> > > > > > > > > Hi Scott,
> > > > > > > > >
> > > > > > > > > I tried that But it didnt work...Any other ideas?
> > > > > > > > >
> > > > > > > > > Thanks
> > > > > > > > >
> > > > > > > > > "Scott M." wrote:
> > > > > > > > >
> > > > > > > > > > Add a space character into the ASC and DESC strings (" ASC" and " DESC").
> > > > > > > > > > If you don't then the sort criteria gets ASC or DESC cocatenated right onto
> > > > > > > > > > the end of the sort string.
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > > "pmud" <pm**@discussions.microsoft.com> wrote in message
> > > > > > > > > > news:83**********************************@microsof t.com...
> > > > > > > > > > > Hi,
> > > > > > > > > > >
> > > > > > > > > > > I am using teh following code for sorting the data grid but it doesnt
> > > > > > > > > > > work.
> > > > > > > > > > > I have set the auto generate columns to false. & set the sort expression
> > > > > > > > > > > for
> > > > > > > > > > > each field as the anme of that field... This grid displayes results based
> > > > > > > > > > > on
> > > > > > > > > > > users search..
> > > > > > > > > > >
> > > > > > > > > > > public static int numberDiv;
> > > > > > > > > > > private void Page_Load(object sender, System.EventArgs e)
> > > > > > > > > > > {
> > > > > > > > > > > // Put user code to initialize the page here
> > > > > > > > > > > }
> > > > > > > > > > > private void btnSearch_Click(object sender, System.EventArgs e)
> > > > > > > > > > > {
> > > > > > > > > > > fn();
> > > > > > > > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > > > > > > >
> > > > > > > > > > > DataGrid1.DataBind();
> > > > > > > > > > > }
> > > > > > > > > > >
> > > > > > > > > > > private void DataGrid1_SortCommand(object source,
> > > > > > > > > > > System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
> > > > > > > > > > > {
> > > > > > > > > > > fn();
> > > > > > > > > > > sqlDataAdapter1.Fill(dsSearch1);
> > > > > > > > > > > DataView dv = new DataView(dsSearch1.Tables[0]);
> > > > > > > > > > > if( (numberDiv%2) == 0 )
> > > > > > > > > > > dv.Sort = e.SortExpression + " " + "ASC";
> > > > > > > > > > > else
> > > > > > > > > > > dv.Sort = e.SortExpression + " " + "DESC";
> > > > > > > > > > > numberDiv++;
> > > > > > > > > > > DataGrid1.DataSource = dv;
> > > > > > > > > > > DataGrid1.DataBind();
> > > > > > > > > > > }
> > > > > > > > > > > private void fn()
> > > > > > > > > > > {
> > > > > > > > > > > sqlSelectCommand1.Parameters.Clear();
> > > > > > > > > > > SqlParameter order=
> > > > > > > > > > > sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
> > > > > > > > > > > if (txtOrder.Text.Equals(String.Empty))
> > > > > > > > > > > {
> > > > > > > > > > > order.Value=System.DBNull.Value;
> > > > > > > > > > > }
> > > > > > > > > > > else
> > > > > > > > > > > {
> > > > > > > > > > > order.Value=int.Parse(txtOrder.Text);
> > > > > > > > > > > }
> > > > > > > > > > > SqlParameter startdate=
> > > > > > > > > > > sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
> > > > > > > > > > > if (txtStartDate.Text.Equals(String.Empty) )
> > > > > > > > > > > {
> > > > > > > > > > > startdate.Value=System.DBNull.Value;
> > > > > > > > > > > }
> > > > > > > > > > > else
> > > > > > > > > > > {
> > > > > > > > > > > startdate.Value=System.DateTime.Parse(txtStartDate .Text);
> > > > > > > > > > > }
> > > > > > > > > > > SqlParameter enddate=
> > > > > > > > > > > sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
> > > > > > > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > > > > > > {
> > > > > > > > > > > enddate.Value=System.DBNull.Value;
> > > > > > > > > > > }
> > > > > > > > > > > else
> > > > > > > > > > > {
> > > > > > > > > > > enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
> > > > > > > > > > > }
> > > > > > > > > > > SqlParameter status=
> > > > > > > > > > > sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
> > > > > > > > > > > if (txtEndDate.Text.Equals(String.Empty) )
> > > > > > > > > > > {
> > > > > > > > > > > status.Value=System.DBNull.Value;
> > > > > > > > > > > }
> > > > > > > > > > > else
> > > > > > > > > > > {
> > > > > > > > > > > status.Value=ddlStatus.SelectedValue;
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > }
> > > > > > > > > > > --
> > > > > > > > > > > pmud
> > > > > > > > > >
> > > > > > > > > >
> > > > > > > > > >

Jul 21 '05 #11
Ya,

That line of code is showing the warning:: possible unintended reference
comparison to get a value comparison, cast left hand side to type string...

Any ideas about this?

"pmud" wrote:
hi,

I used the following code:
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if (!IsPostBack)
{
if (ViewState["sortorder"] == null)
{
ViewState["sortorder"] = "ASC";
}
}
}
private void btnSearch_Click(object sender, System.EventArgs e)
{
fn();
sqlDataAdapter1.Fill(dsSearch1);

DataGrid1.DataBind();
}

protected void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEvent Args e)
{
//Response.Write(numberDiv.ToString());
fn();

sqlDataAdapter1.Fill(dsSearch1);
DataView dv = new DataView(dsSearch1.Tables[0]);
dv.Sort = e.SortExpression + " " + ViewState["sortorder"].ToString();
//toggle sortorder
if (ViewState["sortorder"] == "ASC")
ViewState["sortorder"] = "DESC";
else
ViewState["sortorder"] = "ASC";
DataGrid1.DataSource = dv;
DataGrid1.DataBind();

}
private void fn()
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbT ype.Int);
if (txtOrder.Text.Equals(String.Empty))
{
order.Value=System.DBNull.Value;
}
else
{
order.Value=int.Parse(txtOrder.Text);
}
SqlParameter startdate=
sqlSelectCommand1.Parameters.Add("@StartDate",SqlD bType.DateTime);
if (txtStartDate.Text.Equals(String.Empty) )
{
startdate.Value=System.DBNull.Value;
}
else
{
startdate.Value=System.DateTime.Parse(txtStartDate .Text);
}
SqlParameter enddate=
sqlSelectCommand1.Parameters.Add("@EndDate",SqlDbT ype.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Tex t);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbTy pe.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}

It is still not sorting... I think there is some error in it...I cant find
out... Plz help... Also the build succeeds but it shows a blue mark below the
line..............................if (ViewState["sortorder"] ==
"ASC")..........meaning that it is error but cannot understand whats wrong
here.

Plz help...

Thanks

"jwkjng" wrote:
Yea, like i said before, I would normally use ViewState.
But, that means that that event is being fired, and it doesn't do any sorting?

as for using ViewState, do something like this.

in Page_Load
if (!Page.IsPostback)
if (ViewState["sortorder"] == null)
ViewState["sortorder"] = "ASC";
then in your sortcommand,
dv.Sort = e.SortExpression + " " + ViewState["sortorder"].ToString();
//toggle sortorder
if (ViewState["sortorder"] == "ASC")
ViewState["sortorder"] = "DESC";
else
ViewState["sortorder"] = "ASC";

OK.. and did you try changing the name of your form? I know it sounds
absurd, but just give it a try
"pmud" wrote:
Hi,

You know what...its so strange...i added the response.write & the values the
numberDiv is taking are... 1 , 23, 45, 67, 89........

when i clicked the other column header it took the value 1011....

when i clickd the 3rd colimn heading, i got the value as 1213.....

That is soooo strange.... Can it be bcoz my data grid had more than 30
columns???

"jwkjng" wrote:

> Can you add "Response.Write(numberDiv.ToString());" in the
> DataGrid1_SortCommand event and see if it gets fired at all and it does get
> incremented each time the header is clicked?
>
> Also try changing the name of the form from "form1" to something else and
> try it.
>
>


Jul 21 '05 #12
I don't have time to look at your code but a common problem is

Session["KEY"]="VALUE"; // Error! The left hand operand is of type
object! This is a reference based comparison. Do this:
(String)Session["KEY"]="VALUE"; // content equivalence

http://www.geocities.com/jeff_louie/OOP/oop5.htm

Regards,
Jeff
That line of code is showing the warning:: possible unintended reference
comparison to get a value comparison, cast left hand side to type
string...

Any ideas about this?
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 21 '05 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: pmud | last post by:
Hi, I need to display columns in a data grid based on 7 different queries. Now I have 32 questions: 1. Is it possble to have 1 single data adapter with 7 queries & 1 data set or do I need to...
1
by: Rushabh Dadbhawala | last post by:
Problem: I am fetching data from the database, storing it in a dataSet, and binding it with a Data Grid. The DataGrid controls allows sorting. The problem is that when the data is sorted on one...
2
by: Das | last post by:
Hi, With the data grid I have set the allow sort to true. I aslo know with hittest which column was last sorted. Even thought I sort the dataview with that field but. But then How can I get...
16
by: pmud | last post by:
Hi, I am using teh following code for sorting the data grid but it doesnt work. I have set the auto generate columns to false. & set the sort expression for each field as the anme of that...
3
by: Sam | last post by:
Hi All, I have a very strange issue with ms sql stored procedure and sqlDataReader and I hope that someone can tell me what's going on . I have an asp.net application which has one of its page...
1
by: mbewers1 | last post by:
Hi there I'm trying to add in sorting for the data grid in my web page but nothing happens when I click on the table headers. I've researched the web and developed the code below and set...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.