Solved

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

Posted on 2008-06-24
7
688 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
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

734 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