dynamically change

  • Thread starter Saravanan Rathinavelu
  • Start date
S

Saravanan Rathinavelu

I need to know how to modify the <asp:BoundColumn/> to
N/A when the datafield value comes in as negative
quantity and color it different on the ASP.Net DataGrid,
help me. thanks

-Saravanan.R-
 
L

Lewis Wang [MSFT]

Hi Saravanan,

You may change the negative quantity to N/A and color it in the
DataGrid.ItemDataBound. The following is a code snippet for demonstration.
You can modify it to meet your requirements.

private void DataGrid1_ItemDataBound(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Item
||e.Item.ItemType==ListItemType.AlternatingItem)
{
Label l=new Label ();
l.Text ="N/A";
l.ForeColor =Color.Red;
if (Convert.ToInt32 (e.Item .Cells[3].Text)<0)e.Item
.Cells[3].Controls.Add(l);
}
}

Does this answer your question? Please let me know if you need more
information

Best regards,
Lewis

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
| Content-Class: urn:content-classes:message
| From: "Saravanan Rathinavelu" <[email protected]>
| Sender: "Saravanan Rathinavelu" <[email protected]>
| Subject: dynamically change
| Date: Wed, 20 Aug 2003 13:47:29 -0700
| Lines: 6
| Message-ID: <[email protected]>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcNnXEUjcshcGR3xT4afTQqucDH0SA==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridcontrol
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridcontrol:6294
| NNTP-Posting-Host: TK2MSFTNGXA12 10.40.1.164
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridcontrol
|
| I need to know how to modify the <asp:BoundColumn/> to
| N/A when the datafield value comes in as negative
| quantity and color it different on the ASP.Net DataGrid,
| help me. thanks
|
| -Saravanan.R-
|
 
S

Stevie_mac

In DataGrid_ItemDataBound(...)
Dim lbl as Label
lbl = CType(e.Item.Cells(0).Controls(1), Label)
If Val(lbl.Text) < 0 Then
lbl.Text = "N/A"
e.Item.Cells(0).BackColor = Color.Red
End If

The Label, when rendered, is enclosed in a literal - so Cells(0).Controls(0)
will not get your control, Cells(0).Controls(1) will be your control. In the
example above, i dim a label & cast the contents of Cell 0 Control 1 to it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top