如何在ASP.NET中使用特定给定日期搜索网格中的记录 [英] How do I search records in the grid with a particular given date in ASP.NET

查看:49
本文介绍了如何在ASP.NET中使用特定给定日期搜索网格中的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有耐心访问网格,并且它已经接纳日期和出院日期列,我想提供一个功能来搜索具有特定入院日期的患者,并且需要使用网格本身进行搜索,而不是运行查询,我希望它本身就是这样,

如何在给定的录取日期过滤网格中的记录



请回答我,谢谢你



我尝试了什么:



我是对asp.net来说很新,网格操作对我来说很笨拙和困难,请建议一些来源了解网格操作

i have patient visit grid,and it has admit date and discharge date column, i want to give a feature to search for a patient with particular admit date, and it needs to be searched with the grid itself, not running a query, i want it to be that way itself,
how do i filter records in the grid with a given admit date

please answer me, thank you

What I have tried:

i'm very new to asp.net, grid operations are clumsy and difficult for me, please suggest some source to learn about grid operaations

推荐答案

如果你正在使用ADO.NET用于绑定GridView的DataTable,然后您可以执行以下操作:



If you are using ADO.NET with DataTable for binding your GridView, then you can do something like this:

protected void BindGrid(string searchText){
    using(SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE")){
        using(SqlCommand cmd = new SqlCommand(sql,connection)){
                string sql = "SELECT * FROM TableName WHERE YourFieldName = @Param1";
                cmd.Parameters.AddWithValue("@Param1", searchText);
                DataTable dt = new DataTable();
                SqlDataAdapter ad = new SqlDataAdapter(cmd);
                ad.Fill(dt);

                if (dt.Rows.Count > 0) { //check if the query returns any data
                       GridView1.DataSource = dt;
                       GridView1.DataBind();
                }
                else
                {
                     //No records found
                }
        }

    }
}

protected void Button1_Click(object sender, EventArgs e){
        BindGrid(YourTextBoxID.Text.Trim());
}





上面的代码是基于TextBox值搜索数据库中特定记录的典型方法。您可能需要验证文本以确保验证日期格式。您还可以为TextBox使用MaskEdit或Calendar扩展器控件,以确保输入的日期有效。根据您的数据类型,您可能还需要进行从字符串到日期时间的数据类型转换。



希望有所帮助。



The code above is the typical way to search for a particular records in the database based on a TextBox value. You may need to validate the text to ensure validate dates format. You can also use a MaskEdit or Calendar extender control for your TextBox to ensure that the dates entered is valid. Depending on your datatype, you may also need to do a datatype conversion from string to datetime.

Hope that helps.


这篇关于如何在ASP.NET中使用特定给定日期搜索网格中的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆