如何使用 c#3 使用 asp.net 在特定的网格视图单元格上进行自动换行
how to do word wrap on specific grid view cell with asp.net with c#3
我正在使用 BULK SMS 解决方案做项目。我发现特定地址列的网格视图存在一些问题。我 google 出来并找到了一些解决方案但没有成功,
这是我的网格视图代码:
<asp:TemplateField HeaderText="Address" ItemStyle-Wrap="true">
<ItemTemplate>
<asp:Label ID="lbladdress" runat="server" Text='<%#BreakWordForWrap(DataBinder.Eval(Container.DataItem,"strAddress"))%>' Width="150px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这是我背后的代码:
public string BreakWordForWrap(string StringToBreak)
{
if (string.IsNullOrEmpty(StringToBreak))
{
return string.Empty;
}
string pattern = @"(\S{20})(\S)";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
//return regex.Replace(StringToBreak, "<br/>");
return regex.Replace(StringToBreak, @","); //for space...or use "<wbr>"
}
在这里我想在搜索时分解文本。
这里是我的网格视图屏幕截图。
请大家帮帮我...
要在每个 ,
后添加换行符,仅使用 String.Replace
方法:
public string BreakWordForWrap(string StringToBreak)
{
if (string.IsNullOrEmpty(StringToBreak))
{
return string.Empty;
}
return StringToBreak.Replace(",", ",\n");
}
我正在使用 BULK SMS 解决方案做项目。我发现特定地址列的网格视图存在一些问题。我 google 出来并找到了一些解决方案但没有成功, 这是我的网格视图代码:
<asp:TemplateField HeaderText="Address" ItemStyle-Wrap="true">
<ItemTemplate>
<asp:Label ID="lbladdress" runat="server" Text='<%#BreakWordForWrap(DataBinder.Eval(Container.DataItem,"strAddress"))%>' Width="150px"></asp:Label>
</ItemTemplate>
</asp:TemplateField>
这是我背后的代码:
public string BreakWordForWrap(string StringToBreak)
{
if (string.IsNullOrEmpty(StringToBreak))
{
return string.Empty;
}
string pattern = @"(\S{20})(\S)";
Regex regex = new Regex(pattern, RegexOptions.IgnoreCase);
//return regex.Replace(StringToBreak, "<br/>");
return regex.Replace(StringToBreak, @","); //for space...or use "<wbr>"
}
在这里我想在搜索时分解文本。
这里是我的网格视图屏幕截图。
请大家帮帮我...
要在每个 ,
后添加换行符,仅使用 String.Replace
方法:
public string BreakWordForWrap(string StringToBreak)
{
if (string.IsNullOrEmpty(StringToBreak))
{
return string.Empty;
}
return StringToBreak.Replace(",", ",\n");
}