Filter of Data in Gridview logical error please using asp.net
Posted
by
RajuBabli Abbasi
on Stack Overflow
See other posts from Stack Overflow
or by RajuBabli Abbasi
Published on 2012-04-15T17:25:22Z
Indexed on
2012/04/15
17:28 UTC
Read the original article
Hit count: 302
I wanted to filter the Data in asp.net but my Data is not filtering i have some logical error So please help me for this case i will be very thanks full to those who will help me please consider my code and replay me with code if you can so please i am waiting for your replay thanks again
my asp.cs file is protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DisplayStudentInformation(); } } private void DisplayStudentInformation() { string filter = "%" + filterTextBox.Text + "%"; if (filter == String.Empty) filter = "%"; try { using (SqlDataReader reader = DAC.GetCompanyInformation(filter)) {//reader.Read(); StudentGridView.DataSource = reader; StudentGridView.DataBind(); } } catch (SqlException ex) { StatusLabel.Text = ex.Message; } }
my .aspx file is asp:Table ID="Tabel" runat ="server"> asp:TableRow> asp:TableCell> asp:Label ID="filterLabel" runat ="server" Text ="Company Name Filter:" AssociatedControlID="filterTextBox"> /asp:TableCell> asp:TableCell> asp:TextBox ID="filterTextBox" runat="server" MaxLength ="50"> /asp:TableCell> asp:TableCell> asp:Button ID="refreshButton" runat ="server" Text ="Filter" CausesValidation="false" /> /asp:TableCell> /asp:TableRow> /asp:Table>
My DAC file is public static SqlDataReader GetCompanyInformation(string filter) { SqlDataReader reader; string sql = "SELECT * FROM Student WHERE LastName LIKE @prmLastName "; using(SqlCommand command = new SqlCommand (sql,ConnectionManager.GetConnection())) {//In ExecuteReader we pass the CommandBehavior as singleResult because we need the Single result and also passing the close connection when Datais retriev // command.Parameters.Add("@prmLastName", SqlDbType.VarChar, 25).Value = filter; command.Parameters.AddWithValue("@prmLastName", filter); reader = command.ExecuteReader(CommandBehavior.SingleResult | CommandBehavior.CloseConnection); } return reader; }
Note:- When i don't use the If(!Ispostback)
Condition and simply pass the DisplayStudentInformation(); method in my page load then Data can be filter but with If(!IspostBack ) condition which is also important for updating the data and for other purpose . Data can be filter . Se aim of the expert is that Filter the Data in a gridview using condition of IF(!IspostBack ) means without the removing is post back condition Filter the Data . I have been ask other about this question but no body solve this so please help me i will be very thanks full to you all ok
© Stack Overflow or respective owner