Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi guys,

 

I need some help with the datagrids. I've spent all day with books forums etc. but i can't find a solution that works.

 

How is it possible to control the format of every item based on data from a dataset. For example say i have a field called "Result", what i need is if this field is 0 the row to have a background color red if it is 1 green if 2 blue. So what i need is to control some properties from data of a database. Also another example, i have a datagrid with two button columns one pass one fail, but what i need is that the records that have been evaluated not to display these to buttons.

 

Any ideas or code examples are welcome.

 

Thanks

Posted

In your itemdatabound event do..

 

If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then

 

Select Case e.Item.DataItem("Result")

Case 0

e.item.backcolor = 'your color

'or

e.item.cssclass = 'your style sheet class

Case else ....

End Select

 

Dim myButton As Button = e.item.Findcontrol("btnAdd")

myButton.Visible = False

 

End If

Posted

Thanks a lot that worked,

 

it's very similar to what i've tried up until now,

 

i have a question though

 

if that works fine on the itemboundevent

 

why this doesn't work ?

 

 TextBox1.Text = DataGrid1.Items.Item(1).DataItem("NName")

 

i get a System.NullReferenceException: Object variable or With block variable not set. exception

 

Thanks

Posted

Is this line inside your itemdatabound or outside it? Can I see your whole itemdatabound event code? From the looks of it, if that is inyour itemdatabound, then this part

 

DataGrid1.Items.Item(1).DataItem("NName")

 

You are referring to the item index, which is 1, so you are setting the text of each row to the datagrids 2nd row's dataitem. Now if the itemindex of your databound event is other than 1, then I dont think you can access the DataItem any longer. Use

 

Textbox.text = e.item.dataitem("NName")

 

this will use the current row's data

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...