banner



Vb Net System Drawing Color

  • Remove From My Forums

 locked

Textbox_D_dif.Text.forecolor = System.Drawing.Color.Red - Get error forecolor not a member of string

  • Question

  • User1816379506 posted

    How do I make a textbox in my web form a certain color.

    I have namesplate system.drawing.

    Textbox_D_dif.Text.forecolor = System.Drawing.Color.Red - Get error forecolor not a member of string

    But I get error forecolor not a member of string.  Also, how do I make an entries in a web form listview a certain color.

Answers

  • User281315223 posted

    Problem 1:

    I wish to turn the color to red in using VB code when TEXTBOX_D_INCOME is below 100.00

    <asp:Label ID="Textbox_D_income" style="font-size: large; color: black; font-size: 16px; text-align: right; "

    You could handle this within your Page_Load method by simply checking the value within your TextBox and styling it accordingly :

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load         ' Parse your value as a decimal '         Dim income = 0         ' If your value is a decimal, parse it '         If (Decimal.TryParse(TextBox_D_income.Text, income)) Then             ' It is a decimal, so check if it is below 100 and style accordingly             If income < 1000 Then                 ' Style it red '                 TextBox_D_income.ForeColor = System.Drawing.Color.Red             Else                 ' Style it to the default (black) '                 TextBox_D_income.ForeColor = System.Drawing.Color.Black             End If         End If End Sub

    Problem 2:

    Also, when the value of dtype is D I would like to turn the complete entry in my listview to RED in my VB code .

    runat="server"></asp:Label>

    <td>  <asp:label ID="dtype" runat="server"  text='<%# Eval("dtype")%>' />   </td>

    You could handle this by setting the ForeColor property on the Label the same way as you are setting the value :

    <asp:Label ID="dtype" runat="server" Text='<%# Eval("dtype") %>' ForeColor='<%# If(Convert.ToString(Eval("dtype")) = "D", "Red", "Black") %>'                      />
    • Marked as answer by Thursday, October 7, 2021 12:00 AM
  • User281315223 posted

    The code that you have should absolutely work and be setting the color of your TextBox to Red. I'll demonstrate this with a very basic example seen below :

    Example.aspx

    <!DOCTYPE html>  <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">         <asp:TextBox ID="ExampleTextBox" runat="server" Text="Test"></asp:TextBox>     </form> </body> </html>

    Example.aspx.vb

    Public Class YourPageName     Inherits System.Web.UI.Page      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load         ExampleTextBox.ForeColor = System.Drawing.Color.Red     End Sub  End Class

    Rendered Example

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
  • User281315223 posted

    Alright, if that is the case, then let's assume you have markup like the previous example indicated :

    <form id="form1" runat="server">         <asp:Panel ID="Panel1" runat ="server">             <table>                 <asp:ListView ID="ListView_Budget" runat="server"OnItemDataBound="ListView_Budget_DataBound">                          <ItemTemplate>                         <tr                      id='row' runat="server"                      style="color: #333333;" >                             <td>                                 <asp:LinkButton ID="Linkbutton1" runat="server"  text='Select' Commandname="Select_Sel"  />                                               </td>                             <td>                                 <asp:Label ID="ddate" runat="server"  text='<%# Eval("ddate")%>' />                                                                       </td>                             <td>                                 <asp:Label ID="ddesc" runat="server"  text='<%# Eval("ddesc")%>' />                                               </td>                             <td style="text-align: right;">                                 <asp:Label ID="ddebit" runat="server" text='<%# Eval("ddebit")%>' />                                               </td>                             <td style="text-align: right;">                                 <asp:Label ID="dincome" runat="server"  text='<%# Eval("dincome")%>' />                                               </td>                             <td>                                 <asp:label ID="dmeth" runat="server"  text='<%# Eval("dmeth")%>' />                                               </td>                             <td>                                 <asp:label ID="dcate" runat="server"  text='<%# Eval("dcate")%>' />                                               </td>                                            <td>                                 <asp:label ID="dstatus" runat="server"  text='<%# Eval("dstatus")%>' />                             </td>                             <td>                                 <asp:label ID="dtype" runat="server"  text='<%# Eval("dtype")%>' />                                               </td>                             <td>                                 <asp:label ID="dcomm" runat="server"  text='<%# Eval("dcomm")%>' />                                               </td>                             <td>                                 <asp:LinkButton ID="HistButton" runat="server" Text="History" CommandName ="histcom" />                             </td>                                         </tr>                     </ItemTemplate>                     </asp:ListView>             </table>         </asp:Panel> </form>

    Notice we define an event on your ListView called ListView_Budget_DataBound, we will use this event within your server-side code to read the values in your row and display the color (using the id and runat="server" tags that were added to your row element). In your code-behind, add the following event :

    Protected Sub ListView_Budget_DataBound(sender As Object, e As ListViewItemEventArgs)         ' If this is a data row '         If e.Item.ItemType = ListViewItemType.DataItem Then             ' Find the status column in the row'             Dim status = TryCast(e.Item.FindControl("dstatus"), Label)             If status IsNot Nothing AndAlso status.Text = "????" Then                 ' Then find the row, and paint it red '                 Dim row = CType(e.Item.FindControl("row"), HtmlTableRow)                 row.Attributes.Add("style", "color: red !important")             End If         End If End Sub
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
  • User281315223 posted

    This error means that it couldn't find your element named "row" within the current data item. You'll need to ensure that you set an ID attribute and the runat="server" attribute on your <tr> element within your ItemTemplate as follows :

    <tr id='row' runat="server" style="color: #333333;">     <!-- Contents omitted for brevity --> </tr>
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
  • User281315223 posted

    Add the runat="server" attribute to your <tr> element :

    <tr id="row"                      runat="server"                      style="color: #333333; ">

    This will allow you to access it within your code-behind and set it's background color if your condition is met.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM

Vb Net System Drawing Color

Source: https://forums.asp.net/t/2034725.aspx?Textbox_D_dif+Text+forecolor+System+Drawing+Color+Red+Get+error+forecolor+not+a+member+of+string

Posted by: ryanreephy.blogspot.com

0 Response to "Vb Net System Drawing Color"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel