0

I've created an aspx page and I've created a pege_load function that fills a datagrid. Then a button should filter its data by calling the button_click function, but it's not happening. It does a postback and call Page_load function, but now button_click. How can I make it call button_click and fill the datagrid with the new data? Another strange thing is that IsPostBack is always false. Other events like OnTextChanged are also not firing.

<%@ Page Title ="" Language="C#" AutoEventWireup="True" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="X3M.Views" %>


    <script language="C#" runat="server">
        DataTable dt;
        DataView CartView;
        ICollection CreateDataSource ( )
        {
            DataSet ds = new DataSet( );
            DataTable dt = new DataTable( );
            long firmi_pk = DataManip.SelectInt64("SELECT \"FIRMI_FK\" FROM public.\"POTREBITELI\" where \"USER\" = '" + Session ["username"] + "' and \"PAROLA\" = '" + Session ["password"] + "'");
            ds = DataManip.SelectDataSet("SELECT s.\"IME\" as Име,s.\"KOD\" as Код,c.\"CENA\" as Цена,b.\"BARKOD\" as Баркод,me.\"INICIALI\" as МЕ FROM " +
              "public.\"STOKI_FIRMI\" as sf,public.\"STOKI\" as s,public.\"CENI\" as c, public.\"BARKOD\" b,public.\"MERNI_ED\" me " +
              "where sf.\"FIRMI_FK\" = '" + firmi_pk + "' and sf.\"STOKI_FK\"= s.\"PK\" and c.\"STOKI_FIRMI_FK\" = sf.\"PK\" and b.\"STOKI_FK\" = s.\"PK\"" +
              "and sf.\"MERNI_ED_FK\" = me.\"PK\"");

            dt = ds.Tables [0];

            DataView dv = new DataView(dt);
            return dv;    
        }
        void Page_Load (Object sender, EventArgs e)
        {
            if(!IsPostBack)
            {
                DataGridStoki.DataSource = CreateDataSource( );
                DataGridStoki.DataBind( );
                button1.Click += new EventHandler(button_click);
            }
        }
        void BindGrid ( )
        {
            // Set the data source and bind to the Data Grid control.
            DataGridStoki.DataSource = CartView;
            DataGridStoki.DataBind( );
        }

        void button_click (object sender, EventArgs e)
        {
            CartView = (DataView) DataGridStoki.DataSource;
            string item = TextBox1.Text;
            CartView.RowFilter = "Име ='" + item + "'";
            BindGrid( );
        }
    </script>
    <asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
        Стоки
    </asp:Content>

    <asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <form id="Form2" runat ="server">
    <ul class="nav nav-tabs">
        <li ><a href="AddStoki">Добавяне на стока</a></li>
        <li class="active"><a href="#SpravkaStoki">Справка стоки</a></li>
      </ul>
     <div class="tab-content">
    <div id = "SpravkaStoki" class = "tab-pane fade in active">
    <h3>Стоки</h3>
    <table style ="float: right">
    <tr>
        <td><asp:TextBox ID = "TextBox1" runat ="server" > </asp:TextBox></td>
        <td><asp:button id = "button1" class="w3-button" runat = "server" OnClick = "button_click" Text= "Търси"/></td>
    </tr>
    </table>     
          <asp:DataGrid id="DataGridStoki" runat="server"
               BorderColor="black"
               BorderWidth="1"
               CellPadding="3"
               ShowFooter="true"
               AutoGenerateColumns="true" style="width:100%">


             <HeaderStyle BackColor="#00aaaa">
             </HeaderStyle>
             <FooterStyle BackColor="#00aaaa">
             </FooterStyle>
          </asp:DataGrid>

    </div>
    </div>
    </form>
    </asp:Content>
Ivan
  • 1

0 Answers0