想要创建一个更多的阅读按钮。当我点击该按钮时,应该显示“描述”。特定数据的列。 [英] want to create a read more button. as i click on that button is should display the "description" column for particular data.

查看:49
本文介绍了想要创建一个更多的阅读按钮。当我点击该按钮时,应该显示“描述”。特定数据的列。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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





和我的cs文件编码是





and my cs file coding is

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

    }

推荐答案

据我所知,readmore意味着要显示完整的文章/描述两行三行。

这可以使用javascript或代码隐藏的回发来实现。



1)通过javascript:你可以拥有两个标签首先是截断数据(即两条线),第二个是完整数据。第二个标签最初将使用style =display:none;隐藏。点击按钮时,它会隐藏第一个标签,并使用style =display:block和按钮隐藏显示第二个标签。



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.

<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 - 可以在代码中完成同样的事情后面以及你正在击中服务器然后不需要有两个标签,你可以在最初显示截断的数据第一个标签和按钮回发时,您可以用完整数据替换标签内容。




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.


这篇关于想要创建一个更多的阅读按钮。当我点击该按钮时,应该显示“描述”。特定数据的列。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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