简体   繁体   中英

OnSorting event not firing in GridView

I am reading data from XML and showing it in grid view. Problem is sorting is not working. It doesn't even fire grid3_Sorting method when I click on some column to do sort (I tested it by putting a break point)

This is my grid view and button control.

<asp:Button ID="submit" Text="Submit" runat="server" OnClick="submit_Click" />

<asp:GridView ID="grid3" runat="server" OnSorting="grid3_Sorting" AllowSorting="true"></asp:GridView>

This is code behind.

protected void submit_Click(object sender, EventArgs e)
{
    XmlReader xmlFile;
    xmlFile = XmlReader.Create("myxmlfile.xml", new XmlReaderSettings());
    DataSet ds = new DataSet();
    ds.ReadXml(xmlFile);

    grid3.DataSource = ds.Tables["MyTABLE"];
    grid3.DataBind();
}

protected void grid3_Sorting(object sender, GridViewSortEventArgs e)
{
    DataTable dataTable = grid3.DataSource as DataTable;
    if (dataTable != null)
    {
         DataView dataView = new DataView(dataTable);
         dataView.Sort = e.SortExpression;

         grid3.DataSource = dataView;
         grid3.DataBind();
     }
}

What am I doing wrong?

通过将提交按钮的ID从“ submit”更改为“ sub”进行了修复

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM