|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Trying to get started with tables...If someone could get me started, I can figure the rest out. I'm using visual web 2005 with vb. The following works to change the background color on a table called "table1" Table1.BackColor = Drawing.Color.Blue I would like to programatically change the background color on a row (or column or both) within that table. Could someone point me in the right direction. Thanks Jeff Hi Jeff,
I assume you're referring to <asp:Table> (System.Web.UI.WebControls.Table). Let me know if this is not the case. You could easily use Table.Rows(index) to get a reference to individual row (of type TableRow). From the TableRow reference, you can use TableRow.Cells(index) to get a reference to individual cell (of type TableCell). Both of them also have a property named BackColor which can let you set their background color. I've written following code snippet to demonstrate how to change a row or column's background color: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load ' Add some rows/columns to the table For i As Integer = 1 To 10 Dim tr As New TableRow For j As Integer = 1 To 10 Dim td As New TableCell td.Text = i.ToString + "." + j.ToString() tr.Cells.Add(td) Next table1.Rows.Add(tr) Next ' change third row's background color table1.Rows(2).BackColor = Drawing.Color.Blue ' change third column's background color ' since the table is row-oriented, we need to set the cell row-by-row For i As Integer = 0 To table1.Rows.Count - 1 table1.Rows(i).Cells(2).BackColor = Drawing.Color.Gray Next End Sub Hope this helps. Sincerely, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== Get notification to my posts through email? Please refer to http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif ications. If you are using Outlook Express, please make sure you clear the check box "Tools/Options/Read: Get 300 headers at a time" to see your reply promptly. Note: The MSDN Managed Newsgroup support offering is for non-urgent issues where an initial response from the community or a Microsoft Support Engineer within 1 business day is acceptable. Please note that each follow up response may take approximately 2 business days as the support professional working with you may need further investigation to reach the most efficient resolution. The offering is not appropriate for situations that require urgent, real-time or phone-based interactions or complex project analysis and dump analysis issues. Issues of this nature are best handled working with a dedicated Microsoft Support Engineer by contacting Microsoft Customer Support Services (CSS) at http://msdn.microsoft.com/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. "Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message Yes, I am referring to the above and understand your code example. I'm still news:XlpFcyhKHHA.4020@TK2MSFTNGHUB02.phx.gbl... > Hi Jeff, > > I assume you're referring to <asp:Table> > (System.Web.UI.WebControls.Table). > Let me know if this is not the case. new to this, however, and can't figure out one last (small) thing. If I'm working with a .aspx file in the design view of visual web 2005 with the code-behind file .aspx.vb and if I create a table using the graphical interface of the .aspx file by going to the layout > insert table menu, and subsequently give it the ID of "table1," the code below does not work, as it apparently does not refer to the table I just created with the graphic interface. table1.Rows(2).BackColor = Drawing.Color.Blue if I first declare table1 in the following manner, it still doesn't work (when placed above the code listed above), but it now does not indicate an error - when the thing is run, however, nothing happens. Dim table1 As New Table I know that this is certainly basic, but I'm not sure I understand how to properly link the table in the DUI's design view and the vb code in the codebehind file so that it can be programmatically manipulated. Can you explain further? Jeff "Jeff" <n***@none.com> wrote in message Never mind. I figured it out. ...don't use the layout table from the menu, news:45931456$0$15505$88260bb3@free.teranews.com... > > "Walter Wang [MSFT]" <waw***@online.microsoft.com> wrote in message > news:XlpFcyhKHHA.4020@TK2MSFTNGHUB02.phx.gbl... >> Hi Jeff, >> >> I assume you're referring to <asp:Table> >> (System.Web.UI.WebControls.Table). >> Let me know if this is not the case. > > Yes, I am referring to the above and understand your code example. use the table from the toolbox. Thanks. Jeff Hi Jeff,
Thanks for the update. You might want to check out following resources on how to learn ASP.NET: #INFO: ASP.NET Roadmap http://support.microsoft.com/kb/305140 #Microsoft ASP.NET QuickStarts Tutorial http://www.dotnetjunkies.com/quickstart/aspplus/doc/quickstart.aspx #ASP.NET QuickStart Tutorial http://quickstarts.asp.net/QuickStartv20/aspnet/Default.aspx Please feel free to post in asp.net related newsgroups if you have any questions when you're learning ASP.NET. You can find all managed newsgroups list here: http://msdn2.microsoft.com/en-us/subscriptions/aa974230.aspx For ASP.NET related questions, please use following newsgroups: microsoft.public.dotnet.framework.aspnet microsoft.public.dotnet.framework.aspnet.buildingcontrols microsoft.public.dotnet.framework.aspnet.caching microsoft.public.dotnet.framework.aspnet.datagridcontrol microsoft.public.dotnet.framework.aspnet.mobile microsoft.public.dotnet.framework.aspnet.security microsoft.public.dotnet.framework.aspnet.webcontrols microsoft.public.dotnet.framework.aspnet.webservices Regards, Walter Wang (waw***@online.microsoft.com, remove 'online.') Microsoft Online Community Support ================================================== When responding to posts, please "Reply to Group" via your newsreader so that others may learn and benefit from your issue. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. |
|||||||||||||||||||||||