WorknHardr
asked on
Jquery ASP Gridview Loop Rows Exclude Specific Columns?
I have ASP Gridview I need to loop through all rows except the last row and all columns except the first 3 columns. The dynamic column count will vary from 10 to 15.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I placed my table in jsfiddle and get the top two rows as red. Must be the TH tags?
<table cellspacing="0" rules="all" border="1" id="GridView1" ">
<tr align="center" style="font-family:Arial;font-size:12px;">
<th scope="col">State</th>
<th scope="col">List Name</th>
<th scope="col">EffDate</th>
<th scope="col">Jones-Bob</th><th scope="col"> </th><th scope="col">Smith-Jim</th><th scope="col">
Doe-Jane</th>
</tr><tr align="center" style="font-family:Arial;font-size:10px;">
<td>AK</td><td>List 1</td><td>7/31/2012</td><td> </td><td> </td><td> </td><td>
</td>
</tr><tr align="center" style="font-family:Arial;font-size:10px;">
<td>AK</td><td>List 1b</td><td>7/26/2013</td><td> </td><td> </td><td> </td><td>
Not Priced</td>
</tr><tr align="center" style="background-color:Gainsboro;font-family:Arial;font-size:10px;">
<td>AL</td><td>List 2</td><td>7/1/2012</td><td> </td><td> </td><td> </td><td>$90.00</td>
</tr><tr align="center" style="background-color:Gainsboro;font-family:Arial;font-size:10px;">
<td>AL</td><td>List 2b</td><td>11/15/2013</td><td> </td><td> </td><td> </td><td>$101.00</td>
</tr><tr align="center" style="font-family:Arial;font-size:10px;">
<td>FL</td><td>List 3</td><td>4/1/2013</td><td> </td><td> </td><td>$20.00</td><td>$92.00</td>
</tr>
</table>
Give us a link to the fiddle and tell us what's wrong.
The code I showed you colours all the rows red except the last one, as per your original question.
ASKER
>> except the last row
>> except the first 3 columns.
>> except the first 3 columns.
The code I provided will loop through all the rows except the last one, and for each row it loops through, it will loop through all the TDs except the first 3. That's exactly what you asked for so I'm struggling to see what the problem is.
Can you be a little clearer on what you need.
I've updated the fiddle
Can you be a little clearer on what you need.
I've updated the fiddle
ASKER
I must have VS2010 debug issues, works in js fiddle...
In the HTML you posted, you had the row background colour set inline (style="background-color:G ainsboro;" ) so adding a class that set the background colour will get ignored - inline styles take precedence over class styles, so although the .red class was being added to each of the rows, it had no effect on the last 2.
The fiddle example I've just updated has removed that styling and instead of adding the class to the rows, it now only adds it to the cells.
Maybe why you had a problem with your version :)
The fiddle example I've just updated has removed that styling and instead of adding the class to the rows, it now only adds it to the cells.
Maybe why you had a problem with your version :)
ASKER
I have dynamic columns built in the code-behind like so. It seems the HtmlTextWriter is do some auto-formatting with the row.Backcolor.... Help
protected override void Render(HtmlTextWriter writer)
{
if (GridView1.Rows.Count != 0)
{
Table gridView = (Table)GridView1.Controls[ 0];
foreach (GridViewRow row in GridView1.Rows)
{
row.Cells[6].Text = Convert.ToDateTime(row.Cel ls[6].Text ).ToShortD ateString( );
int rowIndex = gridView.Rows.GetRowIndex( row);
if ((rowIndex - 1) % 4 > 1) //Every 2 rows white
{
row.BackColor = System.Drawing.Color.Gains boro;
}
}
}
base.Render(writer);
}
protected override void Render(HtmlTextWriter writer)
{
if (GridView1.Rows.Count != 0)
{
Table gridView = (Table)GridView1.Controls[
foreach (GridViewRow row in GridView1.Rows)
{
row.Cells[6].Text = Convert.ToDateTime(row.Cel
int rowIndex = gridView.Rows.GetRowIndex(
if ((rowIndex - 1) % 4 > 1) //Every 2 rows white
{
row.BackColor = System.Drawing.Color.Gains
}
}
}
base.Render(writer);
}
Help with what?
You clearly have a line in there that sets the background colour of a row (TR). If you don't want it, remove it (row.BackColor = System.Drawing.Color.Gains boro;)
If you want to override the colour for the selected TDs then just add the background colour to the TDs, and not the TRs.
Can you explain in clear terms exactly what you want. I've shown you the code to select all rows except the last, and all cells except the first 3 as you requested. You haven't at any point told us what you intend to do with the selected cells.
If you want specific answers, you're going to have to ask specific questions
You clearly have a line in there that sets the background colour of a row (TR). If you don't want it, remove it (row.BackColor = System.Drawing.Color.Gains
If you want to override the colour for the selected TDs then just add the background colour to the TDs, and not the TRs.
Can you explain in clear terms exactly what you want. I've shown you the code to select all rows except the last, and all cells except the first 3 as you requested. You haven't at any point told us what you intend to do with the selected cells.
If you want specific answers, you're going to have to ask specific questions
ASKER
Ok, its working now. Nuts, I had to reboot my dev pc, oh well, thanks for ALL your help... thx
ASKER
Excellent, thx again...
With Jquery it can be as simple as
Open in new window