phoenixfire425
asked on
Conditional Formatting on DataGrid and Graphs. asp.net
I have a page that i am working on and i am trying to do a couple of things that i cannot seem to get to work.
First is Conditional Formatting.
I have researched and tried to test a variety of solutions to have a value get highlighted if below a value.
i was using this script in my code behind and i cannot get this to work on the page.
__________
Sub ItemDataBoundEventHandler( sender as Object, e as DataGridItemEventArgs)
If e.Item.ItemType = ListItemType.Item OR _
e.Item.ItemType = ListItemType.AlternatingIt em then
'Check to see if the price is below a certain threshold
Dim price as Double
price = Convert.ToDouble(DataBinde r.Eval(e.I tem.DataIt em, "price"))
If price < 10.0 then
e.Item.BackColor = System.Drawing.Color.Yello w
End If
End If
End Sub
_________________
Second i would like also to have some type of graph on the page to for the datagrid. And I cannot find anything that even gets close to working for me on this. And if there is a possible way can i have a java screen show this on a mouse over?
Lastly is there a way to have the ASP.Net page calculate a value for a column instead of having SQL do this?
Any Help would be great.
Thank You
First is Conditional Formatting.
I have researched and tried to test a variety of solutions to have a value get highlighted if below a value.
i was using this script in my code behind and i cannot get this to work on the page.
__________
Sub ItemDataBoundEventHandler(
If e.Item.ItemType = ListItemType.Item OR _
e.Item.ItemType = ListItemType.AlternatingIt
'Check to see if the price is below a certain threshold
Dim price as Double
price = Convert.ToDouble(DataBinde
If price < 10.0 then
e.Item.BackColor = System.Drawing.Color.Yello
End If
End If
End Sub
_________________
Second i would like also to have some type of graph on the page to for the datagrid. And I cannot find anything that even gets close to working for me on this. And if there is a possible way can i have a java screen show this on a mouse over?
Lastly is there a way to have the ASP.Net page calculate a value for a column instead of having SQL do this?
Any Help would be great.
Thank You
ASKER
i actually just tried that. and i get an error after converting this script to VB. stating that a variable was expected.
AS for the script in your question I plugged it into a datagrid and it worked fine. you may want to inspect other parts of the code, datagrid values and such. And you can have a calculated column like if you send the dataitems to a function. ie below
'basic calculation
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("OASGN")+Eval("WASGN")+Eval("EASGN") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
'more advanced should be sent to a backend function
<asp:TemplateField HeaderText="Percent">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# findpercent((Eval("OASGN")+Eval("WASGN")+ Eval("EASGN")) , Eval("TAUTH")) %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
'backend function
Public Function FindPercent(ByVal total As Double, ByVal auth As Double)
Dim percent As Double = total / auth
Dim spercent As String = percent.ToString("P")
Return (spercent)
End Function
Also is your datagrid tied to the function? if not you may want to add the "handles" directive or make sure the function is tied in.
ASKER
This may sound dumb but i cannot get the handles function to work.
i am not 100% sure if i have the GridView1 tied.
how should i check this?
And i will try the Calulation in the DataGrid Soon as i get the conditional formating done.
Also do you know of anyway to graph data from the DataGrid?
i am not 100% sure if i have the GridView1 tied.
how should i check this?
And i will try the Calulation in the DataGrid Soon as i get the conditional formating done.
Also do you know of anyway to graph data from the DataGrid?
wait are you wanting to use conditional formatting on a DataGrid or a GridView? for the gridview the code is a little different
Sub gv_RowDatabound(ByVal sender As Object, ByVal e As GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
If Convert.ToDouble(DataBinder.Eval(e.Row.DataItem, "price")) < 10.0 Then
e.Row.BackColor = Drawing.Color.Yellow
e.Row.ForeColor = Drawing.Color.Black
End If
End If
End Sub
Well, if you're not using handles the you would need to look at your gridview declaration...you should have the sub specified ie.
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="gv_RowData Bound" AutoGenerateColumns="False " DataSourceID="SqlDataSourc e1">
<asp:GridView ID="GridView1" runat="server" OnRowDataBound="gv_RowData
ASKER
Wow. That sort of worked the way i wanted..
Is there a way for it to just highligh just the column that the row is in ? instead of the entire row?
i guess now i have a bigger question.
What is the main difference between the DataGrid scripting and the Gridview?
Is there a way for it to just highligh just the column that the row is in ? instead of the entire row?
i guess now i have a bigger question.
What is the main difference between the DataGrid scripting and the Gridview?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
since poodles, rings of fire, and small childeren for sacifice are kinda high in demand except poodles but not many want them anyways. haha i am glad i am not taking that route.
i have to use the gridview because of the sorting, paging, and exporting functions.
the code you sent i am assuming that the (1) is the row number. starting at the 0 count and up?
now what about the graphs? is there a simple way of doing this?
i have to use the gridview because of the sorting, paging, and exporting functions.
the code you sent i am assuming that the (1) is the row number. starting at the 0 count and up?
now what about the graphs? is there a simple way of doing this?
ASKER
now for the calulation i am having a hard time with this
if i wanted to take column "FEB" and divide it by "JAN" would the code go
how do you tell the code to Divide?
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FEB")+Eval("JAN")%>' ></asp:Lab el>
</ItemTemplate>
</asp:TemplateField>
if i wanted to take column "FEB" and divide it by "JAN" would the code go
how do you tell the code to Divide?
<asp:TemplateField HeaderText="Total">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("FEB")+Eval("JAN")%>'
</ItemTemplate>
</asp:TemplateField>
Yes the 1 is the column number starting with 0.
As for the graphing, no there isn't really an easy way to do this as you will need to draw the picture. I believe there are a few open source controls for doing this. I can't think of any, but google is a good friend.
Ok for division, it tends to error if you use it inline, I've had better luck sending it to a function.
As for the graphing, no there isn't really an easy way to do this as you will need to draw the picture. I believe there are a few open source controls for doing this. I can't think of any, but google is a good friend.
Ok for division, it tends to error if you use it inline, I've had better luck sending it to a function.
<asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label>
Public Function Dividestuff(ByVal number1 As Double, ByVal number2 As Double)
Dim answer As Double = number1 / number2
Return (answer)
End Function
ASKER
OOUCH!
got this fun error.
what does this mean that i should do?
got this fun error.
what does this mean that i should do?
Parser Error
Description: An error occurred during the parsing of a resource required to service this request. Please review the following specific parse error details and modify your source file appropriately.
Parser Error Message: System.Web.UI.WebControls.DataControlFieldCollection must have items of type 'System.Web.UI.WebControls.DataControlField'. 'asp:Label' is of type 'System.Web.UI.WebControls.Label'.
Source Error:
Line 60: DataFormatString="{0:c}" HeaderText="Dec 07" HtmlEncode="False"
Line 61: SortExpression="Dec 07" />
Line 62: <asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label>
Line 63: <asp:BoundField ApplyFormatInEditMode="True" DataField="Jan" DataFormatString="{0:c}"
Line 64: HeaderText="Jan" ReadOnly="True" SortExpression="Jan">
the label needs to be in a template control
<asp:TemplateField HeaderText="Percent">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label> </ItemTemplate>
</asp:TemplateField>
ASKER
Sorry that was my error
But now i am getting this error.
But now i am getting this error.
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30057: Too many arguments to 'Public Function Dividestuff(number1 As Double, number2 As Double) As Object'.
Source Error:
Line 62: <asp:TemplateField HeaderText="Percent">
Line 63: <ItemTemplate>
Line 64: <asp:Label ID="Label2" runat="server" Text='<%# Dividestuff(Eval("FEB"),Eval("JAN") %>'></asp:Label> </ItemTemplate>
Line 65: </asp:TemplateField>
Line 66: <asp:BoundField ApplyFormatInEditMode="True" DataField="Jan" DataFormatString="{0:c}"
Source File: D:\Repcom\template\Reports\CustomerSalesForYearByMonthWithREPID.aspx Line: 64
ASKER
i got the value working but the only problem is that it displays alot in infinite values and alot o NaN values.
Also i cannot sort using the "Percent" as a sort expression.
would it be better to do the calculation on the SQL side?
Also i cannot sort using the "Percent" as a sort expression.
would it be better to do the calculation on the SQL side?
As for the infinites you can remedy the situation by checking that the divisor is not 0. If your wanting to sort, then yes it would be better to do this one the sqlside.
Hit this link ,where it has shoen how you can change cell's back color as per condition
http://www.codeproject.com/KB/webforms/gridcolumnformatting.aspx
Thanks
Harshad