I want to make all of the cell have their own color
eg,
status = v ---> color Yellow
status = P.H ---> Color Green
status = H -----> Blue
else status ----> Red
This is the code of that situation
Protected Sub gvMonthlyReport_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.Header Then
e.Row.CssClass = "HeaderRow"
e.Row.HorizontalAlign = HorizontalAlign.Center
e.Row.VerticalAlign = VerticalAlign.Middle
End If
'If e.Row.RowType = DataControlRowType.DataRow Then
' e.Row.CssClass = "cellRow"
'End If
If e.Row.RowType = DataControlRowType.DataRow Then
Dim cell As TableCell = e.Row.Cells(17)
Dim status As String = cell.Text
If status = "v" Then
cell.BackColor = Color.Yellow
ElseIf status = "H" Then
cell.BackColor = Color.Blue
ElseIf status = "P.H" Then
cell.BackColor = Color.Green
Else
cell.BackColor = Color.Red
End If
End If
End Sub
this code i have done give me the output color only one column like this
image
output image
actually i want all column , can someone show me?
You have hardcoded cell number 17, but you need to use a loop in the RowDataBound event.
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim i As Integer = 0
Do While (i < e.Row.Cells.Count)
Dim cell As TableCell = CType(e.Row.Cells(i),TableCell)
cell.BackColor = Color.Red
i = (i + 1)
Loop
End If
I have a problem on saving the data that I'm inputting. I have to click the button twice for it to fire up.
I'm trying to add the employee's group details. When I first click the Add button the group details that I'm adding will be successfully added but when i try to add another one again it will not be saved and I have to click the button again for it to be saved or for the button to function.
Here's the codes when I click the Add button
If ValidateGroup() = "" Then
taskoption = Request.QueryString("opt")
If taskoption = "opt_edit" Then
SaveGroup()
disp_Details()
Loadgv()
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
ElseIf taskoption = "opt_add" Then
disp_Blank()
Me.btnSave.Enabled = True
Me.btnUpdate.Enabled = False
ElseIf taskoption = "opt_ae" Then
SaveGroup()
disp_Details()
gvGroup.Visible = True
tblGroup.Visible = True
id_tm1.Visible = True
tblAddGrp.Visible = True
trgd.Visible = False
disp_Group()
Loadgv()
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
End If
Else
Me.MessageBox("alert('Please complete the following: \n" + ValidateGroup() + "\n')")
End If
here's my code in Page_Load
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
userid = getUserid(SessionHandler.UserID, User.Identity.Name.ToUpper(), username)
bol_Admin = isAdmin(userid)
bol_GlobalHR = isGlobalHR(userid)
bol_RegionalHR = isRegionalHR(userid)
bol_LocalHR = isLocalHR(userid)
userEntity = getEntity(userid)
userLocation = getLocation(userid)
userRegion = getRegion(userid)
If KnownUser(userid) Then
If bol_Admin Or bol_GlobalHR Or bol_RegionalHR Or bol_LocalHR Then
If Not Page.IsPostBack Then
Dim win_id As String = User.Identity.Name
loadSetup()
If bol_Admin Or bol_GlobalHR Then
access = "GLOBAL"
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
ElseIf bol_RegionalHR Then
access = "REGIONAL"
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL where region = '" & userRegion & "' ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL where region = '" & userRegion & "' ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL where region = '" & userRegion & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL where region = '" & userRegion & "' ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
ElseIf bol_LocalHR Then
access = "LOCAL"
Dim emp_id As String = Request.QueryString("emp_id")
selectedEmpEntity = getValueString("SELECT entity FROM EMP_MASTERTBL WHERE MASTERID = '" & emp_id & "'")
ehr_utils.fillDDL("SELECT REGION FROM REGION_TBL where region = '" & userRegion & "' ORDER BY REGION", ddl_Region, "REGION", "REGION")
ehr_utils.fillDDL("SELECT COUNTRY FROM COUNTRY_TBL where region = '" & userRegion & "' ORDER BY COUNTRY", ddl_Country, "COUNTRY", "COUNTRY")
'ehr_utils.fillDDL("SELECT ENTITY FROM ENTITY_TBL where entity = '" & userEntity & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT ENTITY FROM LOCALHR_TBL WHERE USERID = '" & userid & "' ORDER BY ENTITY", Me.ddl_Entity, "ENTITY", "ENTITY")
ehr_utils.fillDDL("SELECT LOCATION FROM LOCATION_TBL where entity = '" & selectedEmpEntity & "' ORDER BY LOCATION", ddl_Location, "LOCATION", "LOCATION")
ehr_utils.fillDDL("SELECT DISTINCT C_PERIOD FROM PERIODSETUP_TBL", Me.ddl_period, "C_PERIOD", "C_PERIOD")
ehr_utils.fillDDL("SELECT SUBLOOKUP_NAME FROM SUBLOOKUP_TBL WHERE LOOKUP_NAME = 'YEAR'", Me.ddl_year, "SUBLOOKUP_NAME", "SUBLOOKUP_NAME")
End If
taskoption = Request.QueryString("opt")
updateBtnRmndr.Visible = False
If taskoption = "opt_edit" Then
gvGroup.Columns(9).Visible = True
gvGroup.Columns(10).Visible = True
disp_Details()
Loadgv()
loadSetup()
gvGroup.Visible = True
tblAddGrp.Visible = True
trgd.Visible = False
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
Me.ddl_BusinessUnit.Enabled = True
Me.ddl_SubClassification.Enabled = True
ehr_utils.fillDDL("SELECT BUSINESS_UNIT FROM BUSINESS_UNIT_TBL ORDER BY BUSINESS_UNIT", Me.ddl_BusinessUnit, "BUSINESS_UNIT", "BUSINESS_UNIT")
'Check if the user has access to use the UPDATE ALL function
hasAccess = CheckRecord("SELECT * FROM ACCESSLIST_TBL WHERE MODULE_ID = '1' AND ACCESS = '" & access & "'")
If hasAccess Then 'allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = True
btnUpdateHistoryRecord.Enabled = True
Session("originalEmpNo") = lblval_Empno.Text
updateBtnRmndr.Visible = True
Else ' Not allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
ElseIf taskoption = "opt_ae" Then
gvGroup.Columns(9).Visible = False
gvGroup.Columns(10).Visible = False
gvGroup.Columns(7).Visible = False
trgd.Visible = True
tblAddGrp.Visible = True
Loadgv()
disp_Details()
disp_Group()
gvGroup.Visible = False
tblGroup.Visible = False
id_tm1.Visible = False
Me.btnUpdate.Enabled = True
Me.btnSave.Enabled = False
'Check if the user has access to use the UPDATE ALL function
hasAccess = CheckRecord("SELECT * FROM ACCESSLIST_TBL WHERE MODULE_ID = '1' AND ACCESS = '" & access & "'")
If hasAccess Then 'allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = True
btnUpdateHistoryRecord.Enabled = True
updateBtnRmndr.Visible = True
Session("originalEmpNo") = lblval_Empno.Text
Else ' Not allowed to use the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
Me.ddl_BusinessUnit.Enabled = True
Me.ddl_SubClassification.Enabled = True
ehr_utils.fillDDL("SELECT BUSINESS_UNIT FROM BUSINESS_UNIT_TBL ORDER BY BUSINESS_UNIT", Me.ddl_BusinessUnit, "BUSINESS_UNIT", "BUSINESS_UNIT")
ElseIf taskoption = "opt_add" Then
tblAddGrp.Visible = False
tblGroup.Visible = False
id_tm1.Visible = False
trgd.Visible = False
gvGroup.Visible = False
disp_Blank()
loadSetup()
Me.btnSave.Enabled = True
Me.btnUpdate.Enabled = False
'hide the UPDATE ALL function
btnUpdateHistoryRecord.Visible = False
btnUpdateHistoryRecord.Enabled = False
End If
div_birthDate.InnerText = txtBdate.Text
div_entryDate.InnerText = txtEdate.Text
Else
Dim scriptString As New StringBuilder
scriptString.Append("<script language=JavaScript>")
scriptString.Append("alert('You are not allowed to view this page.');")
scriptString.Append("window.location = 'eHR_Main.aspx';")
scriptString.Append("</script>")
If Not ClientScript.IsStartupScriptRegistered("Startup") Then
ClientScript.RegisterStartupScript(GetType(Page), "Startup", scriptString.ToString())
End If
End If
Else
MessageBox("alert('You're not allowed to view this page.');window.location='eHR_Main.aspx';")
End If
End If
End Sub
Created a master.page and added several content pages. Imported the code from previous webform into one of my content pages. Now the clear button is not working correctly. It will not clear the textboxes or checkboxes. greatly appreciate any help. The form worked perfectly as a standalone page.
vb code:
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim Num1, Num2, Num3, Num4 As Double
Dim Opt1, Opt2, Opt3, Opt4 As Double
Dim BaseTotal, OptionTotal, GrandTotal, Tax As Double
Num1 = Val(TextBox1.Text) * 1500
Num2 = Val(TextBox2.Text) * 70
Num3 = Val(TextBox3.Text) * 90
Num4 = Val(TextBox4.Text) * 130
If CheckBox1.Checked Then
Opt1 = 175
End If
If CheckBox2.Checked Then
Opt2 = 400
End If
If CheckBox3.Checked Then
Opt3 = 100
End If
If CheckBox4.Checked Then
Opt4 = 200
End If
' sum of checkboxes
OptionTotal = Opt1 + Opt2 + Opt3 + Opt4
'total base options
BaseTotal = Num1 + Num2 + Num3 + Num4
' Tax calculation
Tax = (OptionTotal + BaseTotal) * 0.095
GrandTotal = (BaseTotal + OptionTotal + Tax)
'output to text boxes
TextBox5.Text = FormatNumber(BaseTotal, 2)
TextBox6.Text = FormatNumber(OptionTotal, 2)
TextBox7.Text = FormatNumber(Tax, 2)
TextBox8.Text = FormatNumber(GrandTotal, 2)
End Sub
For Each ctrl As Control In form1.Controls
If ctrl.[GetType]() = GetType(TextBox) Then
DirectCast(ctrl, TextBox).Text = String.Empty
ElseIf ctrl.[GetType]() = GetType(CheckBox) Then
DirectCast(ctrl, CheckBox).Checked = False
End If
Next
***************If I use the following code of course it works, however it would be tedious if there were numerous controls on the page.
Protected Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox5.Text = ""
TextBox6.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
CheckBox1.Checked = False
CheckBox2.Checked = False
CheckBox3.Checked = False
CheckBox4.Checked = False
End Sub
Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As EventArgs) Handles Calendar1.SelectionChanged
Dim db As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source='C:\Users\jonhny\Desktop\FinalProject\Backup\Backup\Backup\FinalProject\Database.accdb'")
If db.State = ConnectionState.Open Then
db.Close()
End If
db.Open()
Dim reservationDate As String = Calendar1.SelectedDate
Dim reserved As String
Dim table As String
Dim booking As String = "SELECT BookingDate, NumberOfTable FROM CustomerReservation WHERE BookingDate='" & reservationDate & "'"
Dim sqlcommand1 As New OleDbCommand(booking, db)
Dim dr1 As OleDbDataReader
dr1 = sqlcommand1.ExecuteReader
If dr1.HasRows Then
dr1.Read()
reserved = dr1.Item("BookingDate")
Table = dr1.Item("NumberOfTable")
End If
dr1.Close()
If reservationDate < DateTime.Now.AddDays(-1) Then
lblShowMessage.Text = "*You can't select previous date!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate < DateTime.Now.AddDays(7) Then
lblShowMessage.Text = "*You have to reserve 7 days earlier!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate = reserved Then
lblShowMessage.Text = "*This day not Available!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
Button13.Visible = True
Button14.Visible = True
Button15.Visible = True
Button16.Visible = True
Button17.Visible = True
Button18.Visible = True
If Button1.Text = table Then
Button1.Visible = False
End If
If Button2.Text = table Then
Button2.Visible = False
End If
If Button3.Text = table Then
Button3.Visible = False
End If
If Button7.Text = table Then
Button7.Visible = False
End If
If Button11.Text = table Then
Button11.Visible = False
End If
Else
lblShowMessage.Text = "Available to Reserve"
lblShowMessage.ForeColor = Drawing.Color.Green
lblShowDate.Text = Calendar1.SelectedDate
BookingdateTextBox.Text = Calendar1.SelectedDate
btnPToPayment.Visible = True
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
End If
db.Close()
End Sub
it only can disable 1 button, how can to disable more then 2 button at same time?
I would suggest you change the logic to include a while loop:
dr1 = sqlcommand1.ExecuteReader
Dim count As Integer = dr1.FieldCount
While reader.Read()
For i As Integer = 0 To count - 1
reserved = dr1.Item("BookingDate")
Table = dr1.Item("NumberOfTable")
If reservationDate < DateTime.Now.AddDays(-1) Then
lblShowMessage.Text = "*You can't select previous date!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate < DateTime.Now.AddDays(7) Then
lblShowMessage.Text = "*You have to reserve 7 days earlier!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
ElseIf reservationDate = reserved Then
lblShowMessage.Text = "*This day not Available!"
lblShowMessage.ForeColor = Drawing.Color.Red
lblShowDate.Text = Calendar1.SelectedDate
btnPToPayment.Visible = False
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
Button13.Visible = True
Button14.Visible = True
Button15.Visible = True
Button16.Visible = True
Button17.Visible = True
Button18.Visible = True
If Button1.Text = table Then
Button1.Visible = False
End If
If Button2.Text = table Then
Button2.Visible = False
End If
If Button3.Text = table Then
Button3.Visible = False
End If
If Button7.Text = table Then
Button7.Visible = False
End If
If Button11.Text = table Then
Button11.Visible = False
End If
Else
lblShowMessage.Text = "Available to Reserve"
lblShowMessage.ForeColor = Drawing.Color.Green
lblShowDate.Text = Calendar1.SelectedDate
BookingdateTextBox.Text = Calendar1.SelectedDate
btnPToPayment.Visible = True
Button1.Visible = True
Button2.Visible = True
Button3.Visible = True
Button4.Visible = True
Button5.Visible = True
Button6.Visible = True
Button7.Visible = True
Button8.Visible = True
Button9.Visible = True
Button11.Visible = True
Button12.Visible = True
End If
Next
End While
dr1.Close()
So what this will do is for every row in the data reader it will run the check to set the reserved and table information, then allow you to run the logic against every row rather than against 1 row which is essentially what you are doing currently.
Additional suggestions
Give your buttons meaningful names like : ReserveTableOne, ReserveTableTwo rather than just button1 and button2 - helps when you revisit the code later on.
Change If reservationDate < DateTime.Now.AddDays(-1) to If reservationDate <= DateTime.Now.AddDays(-1) otherwise it'll only do it if it's less than yesterday rather than less than or equal to yesterday - which is what you need.
Change ElseIf reservationDate < DateTime.Now.AddDays(7) to ElseIf reservationDate > DateTime.Now.AddDays(7) which I think should be correct if you only allow people to reserve up to one week ahead, otherwise that won't allow you to reserve tables that are more than 7 days from now.
I am trying to populate hyperlink1 text on my webpage with the link from the selected gridview row. I am not able to get any value back. Any ideas?
Private Sub GridView1_RowCommand(sender As Object, e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridView1.RowCommand
If e.CommandName = "Select" Then
Dim index As Integer = Convert.ToString(e.CommandArgument)
Dim row As GridViewRow = GridView1.Rows(index)
Me.NameTextBox.Text = Server.HtmlDecode(row.Cells(1).Text)
Me.Product1DropDown.SelectedValue = Server.HtmlDecode(row.Cells(2).Text)
Me.Product2DropDown.SelectedValue = Server.HtmlDecode(row.Cells(3).Text)
Me.JobNumberTextBox.Text = Server.HtmlDecode(row.Cells(4).Text)
Me.AdTextBox.Text = Server.HtmlDecode(row.Cells(5).Text)
Me.MediaTypeDropDown.SelectedValue = Server.HtmlDecode(row.Cells(6).Text)
Me.AuthorDropDown.SelectedValue = Server.HtmlDecode(row.Cells(7).Text)
Me.PublicationDropDown.SelectedValue = Server.HtmlDecode(row.Cells(8).Text)
Me.RunDatesTextBox.Text = Server.HtmlDecode(row.Cells(9).Text)
Me.CostTextBox.Text = Server.HtmlDecode(row.Cells(10).Text)
Me.CostCenterTextBox.Text = Server.HtmlDecode(row.Cells(11).Text)
Me.CommentsTextBox.Text = Server.HtmlDecode(row.Cells(12).Text)
Me.HyperLink1.Text = Server.HtmlDecode(row.Cells(13).Text)
Me.HyperLink1.NavigateUrl = Server.HtmlDecode(row.Cells(13).Text)
Me.TextBox1.Text = Server.HtmlDecode(row.Cells(14).Text)
Label14.Text = "Update"
End If
End Sub