protected void GridView1_DataBound(object sender, EventArgs e)
{
foreach (GridViewRow dgrow in GridView1.Rows)
{
String myString, myPattern;
Boolean result;
myPattern = txtSearch.Text;
myString = dgrow.Cells[0].Text;
result = true;
if (isEndsWith == true)
{
if (myPattern.Length > 0)
{
result = myString.EndsWith(myPattern);
dgrow.Cells[0].Text = myString.Substring(0, myString.LastIndexOf(myPattern))
+ HighlightText(myPattern, myString.Substring(myString.LastIndexOf(myPattern)));
}
else result = false;
if (result == false)
dgrow.Cells[0].Visible = false;
}
else
{
if (isStartsWith)
{
if (myPattern.Length > 0)
{
result = myString.StartsWith(myPattern);
dgrow.Cells[0].Text = HighlightText(myPattern, myString.Substring(0,myPattern.Length)) + myString.Substring(myPattern.Length, myString.Length-myPattern.Length);
dgrow.Cells[0].Visible = true;
}
}
else
{
dgrow.Cells[0].Text = HighlightText(myPattern, myString);
dgrow.Cells[0].Visible = true;
}
}
}
}
Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.
Friday, September 14, 2007
Modifying the contents of a GridView after DataBinding
This is more than bare functionality, but it can be simplified by eliminating the contents in foreach brackets.
Subscribe to:
Post Comments (Atom)
Blog Archive
-
▼
2007
(41)
-
▼
September
(13)
- Connecting to Kensoft.net SQL Server 2005 database
- Copying a MDF SQLExpress Database file to SQL Serv...
- Building an AJAX Slide Show in ASP.net
- Proper ViewState use and the coalescing operator
- GridView table headers and iterating over a GridVi...
- DataGridView cell contents and header contents
- HTML Table header accessibility standards
- C# switch statement for DropDownList to update Ima...
- Using XPath for reading attribute and content of XML
- Nested GridView with subtotals, totals, and counts
- Modifying the contents of a GridView after DataBin...
- Highlight search text functions using css tags and...
- C# to run stored procedure after parsing text
-
▼
September
(13)
No comments:
Post a Comment