Ask a Question related to ASP.NET Data Grid Control, Design and Development.
- Larry Dodd #1
Formating a Particular Cell If I have a datagrid and I wanted to format the cell in say Row 6 Column 3
how would I do this. I don't want to format the cell based on the data I
just want to make the cell a different color.
I just need to understand how to tell the datagrid I want to do something to
a particular cell.
Larry Dodd Guest
-
cfgrid - Update a cell based on the value of another cell
I would like to update a hidden cell based on the value of a visible cell. Is this possible? Thanks -
How to set cell background based on cell value when datagrid is displayed
I would like to check a datagrid cell value, and change the color of the cell background, when a datagrid is displayed. I want to do this as early... -
I need to have a tooltip appear over a cell showing data from another cell in the same row.
I have a datagrid with locations from around the world. In hidden cells, I have the Lat and Long of that location. I need to be able to mouseover... -
RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell?
I have an ASP.NET form with a DataGrid and Button. I want to put a RadioButtonList in a DataGrid cell. I bind it to an ArrayList which has a... -
mouseover in cell 1, change in cell 2
let's say i have 2 cells and what i want to create is, if i mouseover the text or image in cell 1, an image or text would appear in cell 2 ... - Ken Cox [Microsoft MVP] #2
Re: Formating a Particular Cell To change a cell in a dynamic grid, you need to catch it as it is being created
and make the changes you want. For example, this will make the cell in row 6,
column 3 (zero-based) blue:
Private Sub DataGrid1_ItemCreated _
(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) _
Handles DataGrid1.ItemCreated
If e.Item.ItemType = ListItemType.Item And e.Item.ItemIndex = 6 Then
e.Item.Cells(3).BackColor = System.Drawing.Color.Blue
End If
End Sub
Does this help?
Ken
MVP [ASP.NET]
--
Microsoft MVPs have a question for *you*: Are you patched against the Worm?
[url]http://www.microsoft.com/security/security_bulletins/ms03-026.asp[/url]
"Larry Dodd" <[email protected]> wrote in message
news:[email protected]..
If I have a datagrid and I wanted to format the cell in say Row 6 Column 3
how would I do this. I don't want to format the cell based on the data I
just want to make the cell a different color.
I just need to understand how to tell the datagrid I want to do something to
a particular cell.
Ken Cox [Microsoft MVP] Guest
- Stevie_mac #3
Re: Formating a Particular Cell Have a look at your other post - i answered it there (ahhh what the hell - here
it is again...)
C'Mon man... Once you know you can handle the ItemDataBound & can access the
current row (e) then you can do just about anything.
Example - Check cell 3 of every row & apply formatting based on the content
of the cell eg...
If e.Item.Cells(3).Text.ToLower Like "*shit*" Then
e.Item.Cells(3).ToolTip = "This Sentence contains a swear word and has
been censored"
e.Item.Cells(3).Text = Replace(e.Item.Cells(3).Text, "shit", "s***")
End If
Any hoo - heres what you want to do...
Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound
If e.Item.ItemIndex = 6 Then
e.Item.Cells(3).BackColor = Color.Pink
e.Item.Cells(3).ToolTip = "This ones pink cos its different!!!"
End If
End Sub
But just incase your not getting this... ItemDataBound is an event that occurs
when you call DataGrid1.DataBind. You need a handler for this event
(DataGrid1_ItemDataBound(...)). It is called for each row of data in your grid.
So test for the Row number (If e.Item.ItemIndex = 6 Then) then do the formatting
on cell 3 (e.Item.Cells(3).BackColor = Color.Pink)
"Larry Dodd" <[email protected]> wrote in message
news:[email protected]..> If I have a datagrid and I wanted to format the cell in say Row 6 Column 3
> how would I do this. I don't want to format the cell based on the data I
> just want to make the cell a different color.
>
> I just need to understand how to tell the datagrid I want to do something to
> a particular cell.
>
>
Stevie_mac Guest
- Stevie_mac #4
Re: Formating a Particular Cell Just an aside note... You asked about Row 6, Cell 3 & technically the code below
will set Cell 3 of Row 6 to Pink, but these are ZERO based indexes - so if you
realy want the 3rd cell of the 6th DataRow then its like this...
If e.Item.ItemIndex = 5 Then
e.Item.Cells(2).BackColor = Color.Pink
e.Item.Cells(2).ToolTip = "This ones pink cos its different!!!"
End If
Just to be absolutely clear and all that!
Good luck - Stevie_Mac.
"Stevie_mac" <[email protected]> wrote in message
news:bhmbpi$chl$[email protected]..here> Have a look at your other post - i answered it there (ahhh what the hell -grid.> it is again...)
>
> C'Mon man... Once you know you can handle the ItemDataBound & can access the
> current row (e) then you can do just about anything.
>
> Example - Check cell 3 of every row & apply formatting based on the content
> of the cell eg...
> If e.Item.Cells(3).Text.ToLower Like "*shit*" Then
> e.Item.Cells(3).ToolTip = "This Sentence contains a swear word and has
> been censored"
> e.Item.Cells(3).Text = Replace(e.Item.Cells(3).Text, "shit", "s***")
> End If
>
>
> Any hoo - heres what you want to do...
>
> Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
> System.Web.UI.WebControls.DataGridItemEventArgs) Handles
> DataGrid1.ItemDataBound
> If e.Item.ItemIndex = 6 Then
> e.Item.Cells(3).BackColor = Color.Pink
> e.Item.Cells(3).ToolTip = "This ones pink cos its different!!!"
> End If
> End Sub
>
>
> But just incase your not getting this... ItemDataBound is an event that occurs
> when you call DataGrid1.DataBind. You need a handler for this event
> (DataGrid1_ItemDataBound(...)). It is called for each row of data in yourformatting> So test for the Row number (If e.Item.ItemIndex = 6 Then) then do the> on cell 3 (e.Item.Cells(3).BackColor = Color.Pink)
>
>
> "Larry Dodd" <[email protected]> wrote in message
> news:[email protected]..>> > If I have a datagrid and I wanted to format the cell in say Row 6 Column 3
> > how would I do this. I don't want to format the cell based on the data I
> > just want to make the cell a different color.
> >
> > I just need to understand how to tell the datagrid I want to do something to
> > a particular cell.
> >
> >
>
Stevie_mac Guest
- Larry Dodd #5
Re: Formating a Particular Cell That is perfect. I ws thinking that the itemindex property was the number of
the cell. Now I now that it is the row that you are on. Thank you for all of
the help. That is exactly what I needed to do.
"Larry Dodd" <[email protected]> wrote in message
news:[email protected]..to> If I have a datagrid and I wanted to format the cell in say Row 6 Column 3
> how would I do this. I don't want to format the cell based on the data I
> just want to make the cell a different color.
>
> I just need to understand how to tell the datagrid I want to do something> a particular cell.
>
>
Larry Dodd Guest




