Solved

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

Posted on 2008-06-24
7
677 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 

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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Word Template Mail merge with vb.net 4 40
Refresh Datagridview from another form 1 28
Check if number is currency 15 29
Create XML 5 33
In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

758 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

19 Experts available now in Live!

Get 1:1 Help Now