Author |
Topic |
jhermiz
3564 Posts |
Posted - 2004-10-01 : 09:09:16
|
Seen too many examples in C# but none in vb.net / asp.netI want to be able to do two things:1) rollover effect on a grid ? I want to be able to roll over rows on a grid and it changes color. How do I accomplish this2) based on some SQL pulling out data from a database I want to change the back color of a grid row for certain data.For instance I have a database that stores issues. For open issues I want it to make the background color of the row light blue. For closed green and for overdue a light red.How can I accomplish this. If anyone has examples please post them!Thanks,Jon |
|
DustinMichaels
Constraint Violating Yak Guru
464 Posts |
Posted - 2004-10-01 : 09:28:50
|
1) You'll have to do javascript for this.2) I assume your using DataGrids, so you should implement the ItemDataBound event of the datagrid. Then you should check to for your particular value, and based on the value you should change the color of your row.Because of requirement 1 you may want to use a Repeater instead of a DataGrid (assuming that your not). With a repeater you can define a javascript function on each of the table rows in your grid. I'm not sure if this is possible using a DataGrid.Dustin Michaels |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-10-01 : 09:54:07
|
I'd use a reapter to make this happen. I'd be much easier to impliment with a Repeater. Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-10-01 : 10:52:55
|
Does the repeater allow for edits and updates to data ?I thought the grid allowed you to have an update/edit buttons to modify data from a database. |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-10-01 : 11:14:18
|
Yes, a repeater will allow for that, but it's a bit harder to code than the datagrid way. I might have some examples of such that I can dig up if needed.Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-10-01 : 11:16:55
|
o that would be great! |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-10-01 : 12:53:45
|
[code]<asp:repeater id="rptUsers" runat="server"> <HeaderTemplate> <TABLE cellSpacing="0" cellPadding="3" width="100%" border="0"> <TR> <TD> <TABLE style="BACKGROUND-COLOR: #000000" cellSpacing="1" cellPadding="3" width="100%"> <tr class="GridHeader"> <td>User</td> <td>Username</td> <td>Password</td> <td>PIN</td> </tr> </HeaderTemplate> <ItemTemplate> <TR class="GridRow"> <td><asp:LinkButton ID="lnkUserDetails" Runat="server" CommandName="UserDetails" CommandArgument='<%#Databinder.Eval(Container.Dataitem, "UserID") %>'><%#Databinder.Eval(Container.Dataitem, "UserFullName") %></asp:LinkButton></td> <td><%#Databinder.Eval(Container.Dataitem, "UserName") %></td> <td><%#Databinder.Eval(Container.Dataitem, "UserPassword") %></td> <td><%#Databinder.Eval(Container.Dataitem, "PIN") %></td> </TR> </ItemTemplate> <FooterTemplate> </TABLE> </TD> </TR></TABLE></FooterTemplate> </asp:repeater>[/code]In the code behind, you'll handle that link (or button etc) like so:[code] Private Sub rptUsers_ItemCommand(ByVal source As System.Object, ByVal e As System.Web.UI.WebControls.RepeaterCommandEventArgs) Handles rptUsers.ItemCommand Select Case LCase(e.CommandName) Case "userdetails" do stuff case "userdelete" 'You'd need to havve different commands for each button end selectend sub[/code]Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
jhermiz
3564 Posts |
Posted - 2004-10-01 : 13:44:12
|
DO I need to bind that to some database table?Where do you place this information? |
 |
|
jhermiz
3564 Posts |
Posted - 2004-10-01 : 14:00:43
|
ok i binded it but how can one modify this and do an update...should a click open a page allow the edit and close and refresh the repeater?What am I losing going with a repeater as opposed to a datagrid...and how can I incorporate the rollover effect I had asked about (background of row changes color when I move from row to row). |
 |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-10-01 : 14:19:15
|
You lose built in Paging and sorting with the repeater. You also lose some of the more advanced features that the datagrid has, but I think Paging and Sorting are the main ones.-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
chadmat
The Chadinator
1974 Posts |
Posted - 2004-10-01 : 14:21:24
|
Oh, and to do the rollover, you need to add a javascript 'onmouseover' event handler for the TR inside the Item template (THat is where it looks like it would go to me, I haven't tried this code).-Chadhttp://www.clrsoft.comSoftware built for the Common Language Runtime. |
 |
|
jhermiz
3564 Posts |
Posted - 2004-10-01 : 14:30:59
|
Hi Chad / Michael.Thanks to both of your help..I think chad's keyword of JS lead me to using the attributes of the item object.For anyone's information here is how I ended up doing it.Dropped a data grid on the page:<%@ Page Language="vb" AutoEventWireup="false" Codebehind="WebForm2.aspx.vb" Inherits="ims.jakah.com.WebForm2"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD> <title>WebForm2</title> <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"> <meta name="CODE_LANGUAGE" content="Visual Basic .NET 7.1"> <meta name="vs_defaultClientScript" content="JavaScript"> <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:DataGrid id="DataGrid1" style="Z-INDEX: 101; LEFT: 104px; POSITION: absolute; TOP: 56px" runat="server"></asp:DataGrid> </form> </body></HTML> Then my page behind example was: Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here 'Put user code to initialize the page here Dim conMyData As SqlConnection Dim cmdSelect As SqlCommand 'try and make a connection conMyData = New SqlConnection(ConfigurationSettings.AppSettings("strConn")) cmdSelect = New SqlCommand("SELECT * FROM Login", conMyData) conMyData.Open() Me.DataGrid1.DataSource = cmdSelect.ExecuteReader() DataGrid1.DataBind() conMyData.Close() End Sub Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DataGridItemEventArgs) Handles DataGrid1.ItemDataBound If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType = ListItemType.AlternatingItem Then e.Item.Attributes.Add("onMouseOver", "this.bgColor='#006600'") e.Item.Attributes.Add("onMouseOut", "this.bgColor='#FFFFFF'") End If End Sub |
 |
|
MichaelP
Jedi Yak
2489 Posts |
Posted - 2004-10-01 : 15:11:46
|
Nice! That's a really slick solution Jon!Michael<Yoda>Use the Search page you must. Find the answer you will.</Yoda> |
 |
|
|