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.
:
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...
:
Change in your code behind
"private" void DataGrid1_SortCommand(object source,
System.Web.UI.WebControls.DataGridSortCommandEventArgs 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.
:
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
:
it says onsortcommand="SortCommand" in your source code.
Please use onsortcommand="DataGrid1_SortCommand"
:
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
ataGrid 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
ataGrid 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
ataGrid>
</form>
</body>
</HTML>
Plz help. It has been almost a week now & this thing isnt working...
:
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.
:
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.DataGridSortCommandEventArgs e)
{
}
private void fn()
{
sqlSelectCommand1.Parameters.Clear();
SqlParameter order=
sqlSelectCommand1.Parameters.Add("@OrderNo",SqlDbType.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",SqlDbType.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",SqlDbType.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Text);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbType.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
:
Can you check the value of numberDiv?
Can you also double-check you SortExpression value?
:
Hi Scott,
I tried that But it didnt work...Any other ideas?
Thanks
:
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.
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.DataGridSortCommandEventArgs 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",SqlDbType.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",SqlDbType.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",SqlDbType.DateTime);
if (txtEndDate.Text.Equals(String.Empty) )
{
enddate.Value=System.DBNull.Value;
}
else
{
enddate.Value=System.DateTime.Parse(txtEndDate.Text);
}
SqlParameter status=
sqlSelectCommand1.Parameters.Add("@Status",SqlDbType.VarChar);
if (txtEndDate.Text.Equals(String.Empty) )
{
status.Value=System.DBNull.Value;
}
else
{
status.Value=ddlStatus.SelectedValue;
}
}
}