Click here to Skip to main content
15,895,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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:---
XML
&

<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>


XML
<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>



The .cs code is:---
C#
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());
        }
}
Posted
Updated 1-Oct-11 1:32am
v3
Comments
hitech_s 1-Oct-11 7:43am    
your query is correct check once..

have you check in database whether records having names started with 'a' or not

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
 
Share this answer
 
Databases are case sensitive in case of Data, change "a" to "A" and then try or use the query suggested by Sergiu
 
Share this answer
 
try this


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



yogesh.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900