Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > Adding control to datagrid

Reply
Thread Tools

Adding control to datagrid

 
 
Trond
Guest
Posts: n/a
 
      05-04-2005
I have an ASP.NET page that is displaying data from a dataset in a datagrid.
All columns are bound. In code behind file i use ItemDataBound event to do
some formatting of some off the columns. Insted of changing the
cell.BackColor = Color.Green; i want to add a checkbox and set it to checked
if true and unchecked if not ( in the else loop). Is this possible?

Best regards
Trond

private void dgMessages_ItemDataBound_1(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)

{

try

{

if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==

ListItemType.AlternatingItem)

{

TableCell cell = e.Item.Cells[7];

long Timediff = long.Parse(cell.Text);

if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 ||
Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 )

{

cell.BackColor = Color.Green;

cell.Text="OK";

}

else

{

cell.BackColor = Color.Red;

cell.Text="-";

}


 
Reply With Quote
 
 
 
 
ural
Guest
Posts: n/a
 
      05-04-2005
Have a
<asp:TemplateColumn HeaderText="Check">
<ItemTemplate>
<asp:CheckBox ID="temp" Runat="server"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateColumn>
in your aspx.
in item databound event handler say
(assume this check box is at the 1 column)
System.Web.UI.WebControls.CheckBox objChck =
(System.Web.UI.WebControls.CheckBox)e.Item.Cells[1].FindControl("temp");

Then based on your condition check or uncheck this objChck.

Hope this helps!!
Ural
"Trond" wrote:

> I have an ASP.NET page that is displaying data from a dataset in a datagrid.
> All columns are bound. In code behind file i use ItemDataBound event to do
> some formatting of some off the columns. Insted of changing the
> cell.BackColor = Color.Green; i want to add a checkbox and set it to checked
> if true and unchecked if not ( in the else loop). Is this possible?
>
> Best regards
> Trond
>
> private void dgMessages_ItemDataBound_1(object sender,
> System.Web.UI.WebControls.DataGridItemEventArgs e)
>
> {
>
> try
>
> {
>
> if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
>
> ListItemType.AlternatingItem)
>
> {
>
> TableCell cell = e.Item.Cells[7];
>
> long Timediff = long.Parse(cell.Text);
>
> if (Timediff == 1 || Timediff == 3 || Timediff == 5 || Timediff == 7 ||
> Timediff == 9 || Timediff==11 || Timediff == 13 ||Timediff == 15 )
>
> {
>
> cell.BackColor = Color.Green;
>
> cell.Text="OK";
>
> }
>
> else
>
> {
>
> cell.BackColor = Color.Red;
>
> cell.Text="-";
>
> }
>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Adding Dynamic Controls to a DataGrid for use with the built in DataGrid Edit/Update functionality davidjgonzalez@gmail.com ASP .Net Datagrid Control 1 03-25-2006 06:55 AM
Adding javascript event to datagrid control Sjaakie Helderhorst ASP .Net 19 07-26-2004 04:10 PM
adding a control to a datagrid dynamically... =?Utf-8?B?QXNoYQ==?= ASP .Net 1 07-19-2004 09:43 AM
Programatically adding a control (DataGrid)? AC ASP .Net 0 01-05-2004 07:51 PM
Control derived from datagrid, problem with adding other control and databinding (VB) Jc Morin ASP .Net Building Controls 1 12-05-2003 07:22 PM



Advertisments