SortCommand not firing

Discussion in 'ASP .Net' started by EatHam, Jan 21, 2004.

  1. EatHam

    EatHam Guest

    OK - I'm a bit new with .NET, so please bear with me.

    My problem is that I cannot get the sort event to fire. If anyone can shed
    some light on this, I would greatly appreciate it.

    Using c#, datagrid in a .ascx control, using a placeholder to put it in the
    parent page.

    Relevant code:

    <asp:datagrid Visible="False"
    id="grdBook" runat="server" AutoGenerateColumns="False"
    AlternatingItemStyle-BackColor="#DFDFDF" GridLines="Vertical"
    AllowSorting="true" AllowPaging="true" AllowCustomPaging="False"
    PageSize="30" OnSortCommand="grdBook_SortCommand">
    <Columns>
    <asp:BoundColumn DataField="Symbol" HeaderText="Symbol"
    SortExpression="Symbol" />
    </Columns>
    </asp:datagrid>

    Code behind:

    private void Page_Load(object sender, System.EventArgs e)
    {
    //Nothing relevant here - I don't want it to bind data and display the grid
    initially
    }


    private void InitializeComponent()
    {
    this.Load += new System.EventHandler(this.Page_Load);
    btnSearch.Click += new System.EventHandler(this.btnSearch_Click);
    grdBook.SortCommand += new
    DataGridSortCommandEventHandler(grdBook_SortCommand);
    }

    public void grdBook_SortCommand(object sender, DataGridSortCommandEventArgs
    e)
    {
    BindData(e.SortExpression.ToString());
    }
    private void btnSearch_Click(object source, System.EventArgs e)
    {
    BindData("EntryTime");
    }

    private void BindData(string strSortString)
    {
    //Build the query for the given order type
    SqlConnection conBook = new
    SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["bookVi
    ew"]);
    conBook.Open();
    string strBookSQL = "This works fine on btnSearch_Click..." +
    strSortString;
    SqlCommand cmdGetBook = new SqlCommand(strBookSQL, conBook);

    SqlDataAdapter daBook = new SqlDataAdapter();

    daBook.SelectCommand = cmdGetBook;

    DataSet dsBook = new DataSet();
    daBook.Fill(dsBook);

    grdBook.DataSource = dsBook.Tables[0];
    grdBook.DataBind();
    lblRecordCount.Text = dsBook.Tables[0].Rows.Count.ToString() + " records
    found.";
    lblPageCount.Text = "Page " + (grdBook.CurrentPageIndex + 1) + " of " +
    grdBook.PageCount + "<br>";

    foreach (System.Web.UI.Control abc in Page.Controls)
    {
    if (abc.GetType().ToString() == "System.Web.UI.HtmlControls.HtmlForm")
    {
    foreach (System.Web.UI.Control def in abc.Controls)
    {
    if (def.ID == "phdBookResults")
    {
    def.Controls.Add(grdBook);
    def.Controls.Add(lblPageCount);
    def.Controls.Add(lblRecordCount);
    lblPageCount.Visible = true;
    lblRecordCount.Visible = true;
    grdBook.Visible = true;
    }
    }
    }
    }
    }
     
    EatHam, Jan 21, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ken Tucker
    Replies:
    2
    Views:
    2,572
    Ken Tucker
    Jul 6, 2003
  2. Steven
    Replies:
    4
    Views:
    1,559
    Steven
    Oct 25, 2003
  3. Ken Tucker

    DataGrid SortCommand not firing using code-behind??

    Ken Tucker, Jul 5, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    205
    Ken Tucker
    Jul 6, 2003
  4. sa siva via .NET 247

    SortCommand and PageIndexChange event not firing

    sa siva via .NET 247, Mar 24, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    160
    Cole Trickle
    May 5, 2005
  5. Leaf

    SortCommand not firing on DataGrid, EVENTTARGET=","

    Leaf, Jun 8, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    2
    Views:
    185
Loading...

Share This Page