By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,660 Members | 1,953 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,660 IT Pros & Developers. It's quick & easy.

Data Grid NOT SORTING

P: n/a
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
Share this Question
Share on Google+
12 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.