Click here to Skip to main content
15,900,907 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
ASP.NET
<asp:DataList ID="dtlist" runat="server" RepeatColumns="4" 
 CellPadding="5" Width="760px" Height="235px" style="margin-top: 0px" >

 <asp:Image ID="imageid1" runat="server" ImageUrl='<%#Eval("image") %>' height="50px" width="50px"/>
 <asp:Label ID="Label1" runat="server" Text='<%#Eval("projectname")%>'>

....

</asp:DataList>


and my cs file coding is

C#
protected void Page_Load(object sender, EventArgs e)
    {
        
        
            bind();
        
    }

    void bind()
    {

        try
        {
            SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["Connect"].ConnectionString);
            SqlCommand cmd = new SqlCommand("select * from real_addproject", con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            da.Fill(ds);
            dtlist.DataSource = ds.Tables[0].DefaultView;
            dtlist.DataBind();
        }
        catch (Exception ex)
        {
            Response.Write("<script LANGUAGE='JavaScript' >alert('" + ex.Message + "')</script>");
        }

    }
Posted
Updated 16-Jul-13 1:19am
v2
Comments
Hemant Singh Rautela 16-Jul-13 7:02am    
You can use description on label control using default visible= false, After that you want to display with particular Row : Then you can find that row and that label & alter its visible property to true.
nikhil-vartak 16-Jul-13 7:22am    
Solution partially depends on how you want to display it?
ZurdoDev 16-Jul-13 7:58am    
What's the question? Where are you stuck?
rranjansir 17-Jul-13 1:20am    
bro i want to display a readmore button in datalist. when i clik on dat button it will show description about that image in same page. Description is in my database table
ZurdoDev 17-Jul-13 7:35am    
You need to put in some effort. You can't expect other people to do your job for you.

1 solution

As I understand readmore meant to show full article/description instead of two-three lines.
this can be implemented using javascript or code-behind postback.

1) Through javascript: You can have two labels first with truncated data (ie two lines) and second with full data. Second label will be hidden initially using style="display:none;". While clicking on button it will hide first label and show second one using style="display:block" and button hides as well.

ASP.NET
<script type="text/javascript">
        function showdata(btn) {
            if (btn.innerText == 'Show More') {
                document.getElementById('lblShort').style.display = 'none';
                document.getElementById('lblLong').style.display = 'block';
                btn.innerText = 'Show Less';
            }
            else {
                document.getElementById('lblShort').style.display = 'block';
                document.getElementById('lblLong').style.display = 'none';
                btn.innerText = 'Show More';
            }
            return false;
        }
    </script>

   <asp:Label runat="server" ID="lblShort" Text="This is some text..."></asp:Label>
           <asp:Label runat="server" style="display:none;" ID="lblLong" Text="This is some text that is truncated but has more data"></asp:Label>
           <asp:LinkButton runat="server" ID="lbToggle" Text="Show More" OnClientClick="javascript:return showdata(this)"></asp:LinkButton>



2) CodeBehind - Same thing can be done at code behind as well as you are hitting server then no need to have two labels you can show truncated data initially on first label and when Button postbacks you can replace content of label with full data.
 
Share this answer
 
v2
Comments
rranjansir 17-Jul-13 5:25am    
can you just write the code please!!
sumit_kapadia 17-Jul-13 6:57am    
Code added ..

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