Solved

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

Posted on 2008-06-24
7
684 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What namespace do I need to import? 2 29
How do you do a one to many list in .NET CORE? 2 28
VB.net and sql server 4 36
VB.Net - MemoryMappedFiles - Confirm receipt 2 19
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

803 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