单击简单按钮"A"然后只显示在asp.net中数据库中第一个字符为"A"的记录,详细信息如下: [英] click on the simple button "A" then only that records is shown which have the first character 'A' from the database in asp.net, Whole details is given below:----

查看:92
本文介绍了单击简单按钮"A"然后只显示在asp.net中数据库中第一个字符为"A"的记录,详细信息如下:的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在asp.net中点击了一个链接按钮.链接按钮的名称为全部".我还使用了一个名称为"A"的按钮.我用一个数据列表控件来从数据库中获取记录.



现在您可以理解,当我单击链接按钮全部"时,所有从数据库中提取并在此之后显示的记录---
现在,我希望当我单击简单按钮"A"时,仅显示数据列表中数据库中第一个字符为"A"的记录.

我正在提供代码,在一段时间之前它可以工作,但现在却不起作用,所以发生了什么,告诉我:-

aspx代码为:---

I have taken a link button in asp.net. The link button name is "All".I have also taken a button which have name "A". I hav etaken a datalist control to fetch the record from the database.



Now u can understand when i click on the link button "All" then all records fetched from the database and shown after that ---
Now I want that when i click on the simple button "A" then only that records is shown which have the first character ''A'' from the database in datalist.

I m giving the code,before some time it was working but now it was not working so what happened ,Tell me:--

The aspx code is:---

&

<asp:Button ID="btnA" runat="server" Text="A" Width="42px" onclick="btnA_Click"/>
<pre lang="xml"><asp:LinkButton ID="lnkbtnAll" runat="server" Font-Underline="False"

                                onclick="lnkbtnAll_Click">All</asp:LinkButton>





<asp:DataList ID="DataList1" runat="server"  RepeatDirection="Horizontal"

        RepeatColumns="1" BackColor="#CCCCCC" BorderColor="#CC9966"

         CellPadding="2"

        onitemcommand="DataList1_ItemCommand" Width="166px" Height="103px"

            >

        <ItemTemplate>
     <asp:LinkButton ID="projectLabel" runat="server" Text='<%# Eval("emplastname") %>' Font-Underline="false" />
         </ItemTemplate>
   </asp:DataList>




.cs代码为:---




The .cs code is:---

protected void lnkbtnAll_Click(object sender, EventArgs e)
    {
        try
        {
            {
                string connectionString = WebConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
                string selectSQL = "SELECT emplastname FROM emppersonalinfo";
                SqlDataAdapter adp = new SqlDataAdapter(selectSQL, cnn);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                Panel1.Visible = true;
                DataList1.DataSource = ds;
                DataList1.DataBind();
            }

        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
       
        Label2.Visible = true;
        Session["pawan"] = "ps";
    }

protected void btnA_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session["pawan"] == "ps")
            {
                string str = "a";
                string connectionString = WebConfigurationManager.ConnectionStrings["cnn"].ConnectionString;
                string selectSQL = "SELECT emplastname FROM emppersonalinfo  where emplastname Like '" + str + "%'";
                SqlDataAdapter adp = new SqlDataAdapter(selectSQL, cnn);
                DataSet ds = new DataSet();
                adp.Fill(ds);
                Panel1.Visible = true;
                DataList1.DataSource = ds;
                DataList1.DataBind();

            }
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
}

推荐答案

Shukla,
您是否尝试过使用不区分大小写的比较(据我所知,您正在使用小写的"a"来寻找"A").您可以将"a"更改为"A",也可以使用不区分大小写的选择查询:
Hi Shukla,
Have you tried using case-insensitive comparison (as far as I see you are looking for "A" using lowercase "a"). You can either change "a" to "A" or use a case insensitive select query:
SELECT emplastname FROM emppersonalinfo  where UPPER(emplastname) Like ''" + str + "%''";


希望对您有帮助,请考虑


Hope this helps, regards


数据库在区分大小写的情况下,将"a"更改为"A",然后尝试或使用Sergiu建议的查询
Databases are case sensitive in case of Data, change "a" to "A" and then try or use the query suggested by Sergiu


尝试一下


try this


string selectSQL = "SELECT emplastname FROM emppersonalinfo  where emplastname Like ''a%''";




yogesh.




yogesh.


这篇关于单击简单按钮"A"然后只显示在asp.net中数据库中第一个字符为"A"的记录,详细信息如下:的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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