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>
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());
}
}