gpt4 book ai didi

c# - 当用户在 richtextbox 中输入大量数据时显示阅读更多选项

转载 作者:太空宇宙 更新时间:2023-11-03 15:23:59 24 4
gpt4 key购买 nike

我有一个 richtextbox 和一个 gridview。

当我将数据输入到richtextbox时,它应该显示在gridview中并保存在数据库中。

现在我的要求是,如果我正在输入一个段落或大量数据,我应该显示一个“readmore”按钮,当点击时,显示完整的数据。

<%@ Register Assembly="FreeTextBox" Namespace="FreeTextBoxControls" TagPrefix="FTB" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Richtextbox Sample</title>
<script type="text/javascript">
function validate() {
var doc = document.getElementById('FreeTextBox1');
if (doc.value.length == 0) {
alert('Please Enter data in Richtextbox');
return false;
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
<FTB:FreeTextBox ID="FreeTextBox1" runat="server">
</FTB:FreeTextBox>
</td>
<td valign="top">
<asp:GridView runat="server" ID="gvdetails" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="RichtextBoxData">
<ItemTemplate>
<asp:Label ID="lbltxt" runat="server" Text='<%#Bind("RichtextData") %>'/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</td>
</tr>
</table>
</div>

<asp:Button ID="btnSubmit" runat="server" OnClientClick="return validate()"
Text="Submit" onclick="btnSubmit_Click" />
<br />
<asp:Label ID="lbltxt" runat="server"/>

</form>
</body>
</html>

c#代码-

SqlConnection con = new SqlConnection("Data Source=SureshDasari;Integrated Security=true;Initial Catalog=MySampleDB");

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
BindGridview();
}

protected void BindGridview()
{
con.Open();
SqlCommand cmd = new SqlCommand("select RichTextData from RichTextBoxData", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
gvdetails.DataSource = ds;
gvdetails.DataBind();
}

protected void btnSubmit_Click(object sender, EventArgs e)
{
con.Open();
SqlCommand cmd = new SqlCommand("insert into RichTextBoxData(RichTextData) values(@Richtextbox)", con);
cmd.Parameters.AddWithValue("@Richtextbox", FreeTextBox1.Text);
cmd.ExecuteNonQuery();
con.Close();
FreeTextBox1.Text = "";
BindGridview();
}

最佳答案

首先在您的选择查询中添加文本的 ID(您的表 RichTextBoxData 的主键)并在 gridview 中使其可见 =false 像这样

       <asp:TemplateField HeaderText="id" InsertVisible="False" Visible="False">

<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("id") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>

然后

    protected void gvdetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{


Label lb =e.Row.FindControl("lbltxt") as Label;

if (lb.Text.Length > 15)//any length u want
{

DataRow drv = ((DataRowView)e.Row.DataItem).Row;

int tempID = Convert.ToInt32(drv["id"].ToString());

HyperLink hp = new HyperLink();
hp.Text = "read more";
hp.NavigateUrl = "~/mydetails.aspx?id=" + tempID;
e.Row.Cells[1].Controls.Add(hp);
lb.Text = lb.Text.Substring(0, 15);


}

}
}

在 mydetails.aspx 的 page_load 上查询以选择 RichTextData where id=request.querystring["id"]

关于c# - 当用户在 richtextbox 中输入大量数据时显示阅读更多选项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36091516/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com