Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a datalist with several rows and at the end inside the datalist I have Button 'Btndetails' and a Lable LblDetails'. The repeat columns is set to 3. Each column has button 'Btndetails'.
On click of this button I want to show a Label 'LblDetails' to the user. It works. But the Label
is shown at the last column of the datalist for which the user has to scroll and read. I want this
Label to be shown near to that button itself, on the same column itself. How to do it?

XML
<asp:DataList ID="DataList1" runat="server"   BackColor="White"   Width="220" BorderStyle="None"    BorderWidth="2" OnItemCommand="dl_item_command" RepeatColumns="3"   style=" border-top-style:groove; border-top-color:Lime; border-left-width:medium;"   RepeatDirection="Horizontal"  >
<asp:UpdatePanel ID="dd" runat="server"    >
<ContentTemplate>
 <asp:Button ID="AddToCart"  runat = "server" Text='Add to Cart'   BackColor="#cccccc" Width="100px"  Style=" font-family:Arial" ForeColor="#333333" commandname="myevent">
 </asp:Button>
 <asp:Button ID="BtnDetails"  runat = "server" Text='Details'   BackColor="DarkSlateBlue" Width="100px"  Style=" font-family:Arial" ForeColor="White" commandname="myeventDetails">
 </asp:Button>
 <asp:Label ID="Lbldetails" runat="server" Visible="false" Height="197" BackColor="Black"    ForeColor="GhostWhite" style=" size:auto; overflow:auto; position:absolute;   width:246px"> </asp:Label>

C#
if (e.CommandName == "myeventDetails") // check commandname here
       {
           int index = e.Item.ItemIndex;
         //  Button dd = (Button)DataList1.Items[index].FindControl("BtnDetails");
           Label lbl1 = (Label)DataList1.Items[index].FindControl("lblProductId");
           v_code = Convert.ToInt32(lbl1.Text);
           Label CategoryLbl = (Label)DataList1.Items[index].FindControl("CategoryLbl");
           v_categoryid = Convert.ToInt32(CategoryLbl.Text);
           SqlCommand cmd4 = new SqlCommand("SELECT DescriptionStatic from product WHERE CategoryId='" + v_categoryid + "' and ProductId='" + v_code + "'", con);
       SqlParameter param4 = new SqlParameter();
       param4.ParameterName = "@v_mem_id1";
       param4.Value = "ss";
       cmd4.Parameters.Add(param4);
       con.Open();
       SqlDataReader reader1 = cmd4.ExecuteReader();
       if (reader1.HasRows)
       {
           while (reader1.Read())
           {
               string v_descriptionstatic = reader1.GetString(0);
               Lbldetails.Text = Convert.ToString(v_descriptionstatic);
               //Lbldetails.Style[HtmlTextWriterStyle.Top] = "610px";
               Lbldetails.Visible = true;
Posted
Updated 14-Mar-14 0:38am
v2

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