Hi Frndz,
Functionality: Set textbox width inside GridView
For that ,
- Set Header Style Width
- Set Item Style Width
- Set Textbox Width
- If your string is too much long then you need to break your string dynamically
Create one function which break the string after specific number of character.
Check BreakLongString Function for break the string.
Pass BreakLongString Function as
Text='<%# BreakLongString(Eval("Value").ToString(),30) %>'
There is two argument.
- Pass the original string
- Pass number (Break string after ths number)
Logic:
Textbox inside Templatefield
<asp:TemplateField HeaderStyle-Width="80px" ItemStyle-Width="80px">
<ItemTemplate>
<asp:TextBox ID="txtLongString" Width="80px" runat="server" Text='<%# BreakLongString(Eval("Value").ToString(),30) %>'></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
Function for Break Long String
public string BreakLongString(string SubjectString, int CharsToBreakAfter)
{
string Pattern = "\\S{" + CharsToBreakAfter + ",}";
int Counter = 0;
bool IsMatching = Regex.IsMatch(SubjectString, Pattern);
while (IsMatching)
{
Counter++;
string MatchedString = Regex.Match(SubjectString, Pattern).Value;
SubjectString = SubjectString.Replace(MatchedString.Substring(0, (CharsToBreakAfter - 1)), MatchedString.Substring(0, (CharsToBreakAfter - 1)) + " ");
// Prevent endless loops
if (Counter > 20) break;
// Check if we still have long strings
IsMatching = Regex.IsMatch(SubjectString, Pattern);
}
return SubjectString;
}
Hope this helpful!
Thanks