C# 文本过多的GridView
我有一个GridView,它从数据库中提取数据并自动填充其字段C# 文本过多的GridView,c#,asp.net,gridview,C#,Asp.net,Gridview,我有一个GridView,它从数据库中提取数据并自动填充其字段 <asp:GridView ID="gvData" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True" DataSourceID="DS" Page
<asp:GridView ID="gvData" runat="server" CellPadding="4"
ForeColor="#333333" GridLines="None" AllowPaging="True" AutoGenerateDeleteButton="True"
AutoGenerateEditButton="True" DataSourceID="DS" PageSize="1" CssClass="q">
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" Height="20" CssClass="q"/>
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#284775" ForeColor="White" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#999999" Height="15px" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
<asp:SqlDataSource ID="DS" runat="server"></asp:SqlDataSource>
有些田地太长了。有没有办法缩短文本的长度并插入一个按钮,弹出一个包含文本的新窗口?
gridview还生成编辑和删除按钮。按一个编辑按钮给我一些文本框。我怎样才能绕过它们,使同一个按钮有一个弹出窗口进行编辑
我想到的另一种方法是用滚动条创建文本区域。我知道如何手动添加带有滚动条的字段,但它是作为标签创建的,因此当我按Edit时,此字段不可编辑。同样,它是手动的,但我的gridview是自动填充的。如何用滚动条自动填充文本区域的大字段
任何帮助都将不胜感激!谢谢大家!
好的,我找到了一个缩短文本的解决方案:
protected void gvData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
ViewState["OrigData"] = e.Row.Cells[i].Text;
if (e.Row.Cells[i].Text.Length >= 30)
{
e.Row.Cells[i].Text = e.Row.Cells[i].Text.Substring(0, 30) + "...";
e.Row.Cells[i].ToolTip = ViewState["OrigData"].ToString();
}
}
}
}
受保护的void gvData\u RowDataBound(对象发送方,GridViewRowEventArgs e)
{
如果(e.Row.RowType==DataControlRowType.DataRow)
{
for(int i=0;i=30)
{
e、 Row.Cells[i].Text=e.Row.Cells[i].Text.Substring(0,30)+“…”;
e、 Row.Cells[i].ToolTip=ViewState[“OrigData”].ToString();
}
}
}
}
然后添加OnRowDataBound=“gvData\u RowDataBound”:
这将长度减少到30个字符,并在工具提示中显示全文。看看这篇文章,我认为它可能很有用
对第二部分的回答:
protected void gvData_PreRender(object sender, EventArgs e)
{
if (this.gvData.EditIndex != -1)
{
TextBox tb = new TextBox();
for (int i = 0; i < gvData.Rows[gvData.EditIndex].Cells.Count; i++)
try
{
tb = (TextBox)
gvData.Rows[gvData.EditIndex].Cells[i].Controls[0];
if (tb.Text.Length >= 30)
{
tb.TextMode = TextBoxMode.MultiLine;
}
}
catch { }
}
}
protectedvoid gvData\u预渲染(对象发送方,事件参数e)
{
如果(this.gvData.EditIndex!=-1)
{
TextBox tb=新的TextBox();
对于(int i=0;i=30)
{
tb.TextMode=TextBoxMode.MultiLine;
}
}
捕获{}
}
}
对不起,我没有提到,我正在制作一个web应用程序,而不是表单。但是谢谢你的链接!哈哈,好吧,也许这个链接是有用的,这是相当硬编码的。我有大约30个字段,它们可能会不时变化。。。
protected void gvData_PreRender(object sender, EventArgs e)
{
if (this.gvData.EditIndex != -1)
{
TextBox tb = new TextBox();
for (int i = 0; i < gvData.Rows[gvData.EditIndex].Cells.Count; i++)
try
{
tb = (TextBox)
gvData.Rows[gvData.EditIndex].Cells[i].Controls[0];
if (tb.Text.Length >= 30)
{
tb.TextMode = TextBoxMode.MultiLine;
}
}
catch { }
}
}