Solved

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

Posted on 2008-06-24
7
689 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
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.
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…

627 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