Solved

webform(asp.net 1.1(vb.net)) datagrid, row value selection and apply some validation

Posted on 2008-06-24
7
682 Views
Last Modified: 2013-11-05
My stored procedure will retrun some values from database and i will fill a dataset dsResult using  a dataadaptor

my dataset dsResult.tables(0) look like this

PartNoID     Name   Currency     Country
1             XYZ            10            Japan
2              YZR           0.1           Malaysia
3             RMN          20             Greece

I have my set webform grid grdOpenOrder dataset as dsResult and will show the result in a grid
            grdOpenOrder.DataSource = dsResult
            grdOpenOrder.DataKeyField = "PartNoID "
            grdOpenOrder.DataBind()

my html page will be shown as below
<asp:BoundColumn DataField="PartNoID" HeaderText="Item No"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Quantity"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRENCY" HeaderText="Currency"></asp:BoundColumn>
<asp:BoundColumn DataField="Country" HeaderText="Country"></asp:BoundColumn>

How do show row of records which has currency value is less than one in red colour in datagrid, and while binding into datagrid

grdOpenOrder will look like this

PartNoID     Name   Currency     Country
1             XYZ            10            Japan
2              YZR           0.1           Malaysia -       this row  in red colour
3             RMN          20             Greece

0
Comment
Question by:nyeesg1984
  • 4
  • 3
7 Comments
 
LVL 43

Expert Comment

by:TimCottee
ID: 21853375
Hello nyeesg1984,

You need to use the Item_DataBound event of the grid to achieve this.

    Private Sub grdOpenOrder_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdOpenOrder.ItemDataBound
      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        If CType(e.Item.Cells(2).Text,Double) < 1 Then
           e.Item.BackColor=Drawing.Color.Red
        End If
      End If
    End Sub

Regards,

TimCottee
0
 

Author Comment

by:nyeesg1984
ID: 21853616
Looks great.  How do i call this. here is my current code.
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           
If Not Page.IsPostBack Then
         
           BindData()
End If
End Sub

Private BindData()
 Dim objOrder As New clsOrder
 Dim dsResult As New DataSet
 Dim strmessage As String
 strmessage = objOrder.GenerateOpenOrder(dsResult)
grdOpenOrder.DataSource = dsResult
grdOpenOrder.DataKeyField = "PartNoID "
grdOpenOrder.DataBind()
End Sub
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21853626
You don't need to call it as such, simply add it to your code-behind. Because it handles the ItemDataBound event of the grid, it will be fired automatically for each row as the data is being bound in the .DataBind() method.
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

Author Comment

by:nyeesg1984
ID: 21853772
simply add it to your code-behind -
mean in html code or .vb.  -- i may sound stupid.. sorry.
What you have given is a procedure right. can i call it after BindData()
 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
           
If Not Page.IsPostBack Then
         
           BindData()
grdOpenOrder_ItemDataBound(xxxxxxxxxx) what to pass in here??
End If
End Sub

Private BindData()
 Dim objOrder As New clsOrder
 Dim dsResult As New DataSet
 Dim strmessage As String
 strmessage = objOrder.GenerateOpenOrder(dsResult)
grdOpenOrder.DataSource = dsResult
grdOpenOrder.DataKeyField = "PartNoID "
grdOpenOrder.DataBind()
End Sub

If it is is html code  then where do i call this
<asp:BoundColumn DataField="PartNoID" HeaderText="Item No"></asp:BoundColumn>
<asp:BoundColumn DataField="Name" HeaderText="Quantity"></asp:BoundColumn>
<asp:BoundColumn DataField="CURRENCY" HeaderText="Currency"></asp:BoundColumn>
<asp:BoundColumn DataField="Country" HeaderText="Country"></asp:BoundColumn>
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 21853902
In the Code-behind file (default.aspx.vb for example). You don't even need to call this code, it is called automatically by the .DataBind() method.


 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

           

If Not Page.IsPostBack Then

         

           BindData()

grdOpenOrder_ItemDataBound(xxxxxxxxxx) what to pass in here??

End If

End Sub
 

Private BindData()

 Dim objOrder As New clsOrder

 Dim dsResult As New DataSet

 Dim strmessage As String

 strmessage = objOrder.GenerateOpenOrder(dsResult)

grdOpenOrder.DataSource = dsResult

grdOpenOrder.DataKeyField = "PartNoID "

grdOpenOrder.DataBind()

End Sub
 

Private Sub grdOpenOrder_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdOpenOrder.ItemDataBound

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

   If CType(e.Item.Cells(2).Text,Double) < 1 Then

      e.Item.BackColor=Drawing.Color.Red

   End If

  End If

End Sub

Open in new window

0
 

Author Comment

by:nyeesg1984
ID: 21854158
Awesome...  I am done..

for learning purpose i need to read more  on item_Data bind) event.

Just wonder, is there any i can highlight currency cell only in red, now the entire row will be red colour.
Anyway thanks lot for your great advice....
0
 
LVL 43

Accepted Solution

by:
TimCottee earned 500 total points
ID: 21854235
nyeesg1984,

    Private Sub grdOpenOrder_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles grdOpenOrder.ItemDataBound
      If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then
        If CType(e.Item.Cells(2).Text,Double) < 1 Then
           e.Item.Cells(2).BackColor=Drawing.Color.Red
        End If
      End If
    End Sub

And that is it!

TimCottee
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now