Hello all. I have a very strange and interesting DataGrid issue that I've been pulling my hair out at for 2 days now. I'm updating a web-based timekeeping program (if you want to call it that) for my company. There is a certain interface which allows admins to basically edit any information for any employee. I have a DataGrid in this interface with several templatecolumns and a dropdownlist and literal associated with each as well as a button column. I have it in dropdownlists and literals because the admin can choose to edit whatever they want and then basically do a bulk edit.
Anyway, the template columns and dropdownlists have information such as: Record #, Employee, Date, Hours, Project, Task, Comments, etc. The DataGrid is created only after the admin chooses a date range and either an employee or a project. When the datagrid is created, it can have several entries (lines/rows) with the information I said above depending on the date range.
So, the problem... When the DataGrid is initially created, it looks fine. For example, with the sample data I'm using, I get 3 rows with the correct column information in each of the appropriate dropdownlists. Now, the bulk edit works fine here, but that's not the issue. If I select the Edit button in the button column (to edit a single row), and I update the information and hit my Update button, it updates successfully but I have it force the datagird to disappear. Thus I must click on my Show Data button again to make it reappear and see the changes (if I wanted to). When I do this, this is where the problem comes in. It shows the 3 rows, but in the exact row that I just updated all of the dropdownlists are completely empty when, obviously, they shouldn't be. Though the data that's not in dropdownlists, like the date, hours, and comments are just fine. Now it doesn't matter what I do, that same row will stay empty. Even if I chose a completely different employee and different information, that exact same row (even though the actual data doesn't relate at all to the previous data I updated) is still empty. The only way right now for me to fix this is to completely exit the site and come back in.
I have no idea why it's doing this as everything is set for it to show the data properly and all other rows work fine. It's only that one row, no matter which data is there, that's empty. Has anyone had a similar experience of may have a suggestion? I'd be happy to provide some more details if needed, but I was just trying to give a bried overview for my first post. Thanks! :-)
Oh, and BTW, I'm programming in VB.NET and ASP.NET 1.1. :-)
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
To clarify, the Bulk Editing option works fine. When I'm seeing all 3 rows when I first come to the page and whatnot, I can change any dropdowns and whatnot that I like, hit the Bulk Edit button, and then hit the Show Data button and all shows up fine. It's only when I choose to edit a single row by hitting the Edit button and then after I change the data and hit the Update button and then hit the Show Data button again, it's here where the row disappears, unless I exit and re-enter the entire page. And the only data that has disappeared is in the dropdownlists as the other columns which don't have dropdownlists have the correct and updated data there.
I did some more testing with this and found that if I do a simple response.redirect() to the same page as part of the Update button function, then when I hit the Show Data button, all is OK. BUT, this then clears all other data such as the previously entered data range and employee name, etc., so I must re-enter that information to show the same data as before. This makes it quite cumbersome and which is why I don't want to do the response.redirect.
Any other suggestions? Thanks.
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
is there any chance you could post the code (if you do not want it to be public let me know) I would strangly advise against the response.redirect. It sounds like a error in the coding of either the update or the show data button. im not sure which one yet.
Well, I can post what I can, but it's going to be a lot. Here it is though (hopefully it shows up OK):
Update Button
Code:
Sub IBUpdate_Click(sender As Object, e As ImageClickEventArgs)
EmpID = dropemployee.selecteditem.value
AdminEmpID = session("AdminEmpID")
rLocked = "N"
rDeleted = "N"
IF (checkBoxLocked.Checked) THEN
rLocked = "Y"
Else if cbDeleted.checked = true then
rLocked = "D"
Else if cbDeleted.checked = true and checkboxLocked.checked = true then
rLocked = "Y"
cbDeleted.checked = false
END IF
rdate = session("theselecteddaydate")
Dim dtemp As DateTime = rdate
Dim rMonth = dtemp.tostring("MM")
Dim rDay = dtemp.tostring("dd")
Dim rYear = dtemp.tostring("yyyy")
RHours = Double.Parse(TextHours.text)
RProject = DropProject.selecteditem.text
RProjectV = DropProject.selecteditem.value
RPhase = DropPhase.SelectedItem.text
RPhaseV = DropPhase.selecteditem.value
RTask = DropTask.SelectedItem.text
RTaskV = DropTask.selectedItem.value
RCLIN = DropCLIN.SelectedItem.text
RClinV = DropCLIN.selectedItem.value
RComments = TextComments.text
Dim updtime as DateTime = datetime.now
rcomments = rcomments.replace("'", "''")
Dim gettaskkey As Integer
cmdSelect = New SqlCommand("Select taskkey from task where projectid='" & RProjectV & "' and phaseid='" & RPhaseV & "' and taskid='" & RTaskV & "'", sqlconn)
sqlconn.Open()
gettaskkey = cmdSelect.ExecuteScalar()
sqlconn.Close()
Dim strUpdate as String
Dim CmdUpdate as SqlCommand
strUpdate = "Update Hours set wdate='" & rdate & "', whours='" & rhours & "', Clin='" & rclinv & "', comment='" & rcomments & "', modDate='" & updtime & "', modBy='" & AdminEmpID & "', EmpID='" & Empid & "', taskkey='" & gettaskkey & "', complete='" & rLocked & "', wmonth='" & rmonth & "', wday='" & rday & "', wyear='" & ryear & "' where rec_num= '" & ridnum & "'"
cmdUpdate = New Sqlcommand (strUpdate, sqlconn)
sqlconn.open()
' Session("Message") = "<h3>" & strUpdate & "</h3><br><br>"
cmdUpdate.executenonquery()
sqlconn.close()
session("wdate") = DateTime.Now
response.Redirect("limitedgodentry.aspx")
' labelid.forecolor = system.drawing.color.lightgreen
' labelid.text = "Successfully updated entry!."
' ClickProcessing()
End Sub
Show Data Button
Code:
dispreport.visible = true
if cbEmployee.checked = false
dispreport.columns(2).visible = false
else
dispreport.columns(2).visible = true
end if
if cbDate.checked = false
dispreport.columns(3).visible = false
else
dispreport.columns(3).visible = true
end if
if cbHours.checked = false
dispreport.columns(4).visible = false
else
dispreport.columns(4).visible = true
end if
if cbProject.checked = false
dispreport.columns(5).visible = false
else
dispreport.columns(5).visible = true
end if
if cbPhase.checked = false
dispreport.columns(6).visible = false
else
dispreport.columns(6).visible = true
end if
if cbTask.checked = false
dispreport.columns(7).visible = false
else
dispreport.columns(7).visible = true
end if
if cbClin.checked = false
dispreport.columns(8).visible = false
else
dispreport.columns(8).visible = true
end if
if cbComment.checked = false
dispreport.columns(9).visible = false
else
dispreport.columns(9).visible = true
end if
' Employee lock...
if cbComplete.checked = false
dispreport.columns(10).visible = false
else
dispreport.columns(10).visible = true
end if
' Admin lock...
if cbCooked.checked = false
dispreport.columns(11).visible = false
else
dispreport.columns(11).visible = true
end if
Dim RProject, RProjectV, RPhase, RPhaseV, RTask, RTaskV, RCLIN, RClinV
RProject = DropProject.selecteditem.text
RProjectV = DropProject.selecteditem.value
' IF (String.Compare(RProject, "-") <> 0) THEN
RPhase = DropPhase.SelectedItem.text
RPhaseV = DropPhase.selecteditem.value
' IF (String.Compare(RPhase, "-") <> 0) THEN
RTask = DropTask.SelectedItem.text
RTaskV = DropTask.selectedItem.value
' END IF
' END IF
RCLIN = DropCLIN.SelectedItem.text
RClinV = DropCLIN.selectedItem.value
session("ProjNumChg") = RProjectV
session("PhaseNum") = RPhaseV
'Use Cases
'Project=- Clin=- Do the query on dates only
'Project=- Clin=Not- Do the query on dates + Clin
'Project=Not- Phase=- Clin=- Do the query on Project Only
'Project=Not- Phase=- Clin=Not- Do the query on Project and Clin
'Project=Not- Phase=Not- Clin =- Do the query on Project,Phase only
'Project=Not- Phase=Not- Clin =Not- Do the query on Project,Phase,Clin
'Project=Not- Phase=Not- Task=Not- Clin=- query on Project,Phase,Task
'Project=Not- Phase=Not- Task=Not- clin=Not- use project,phase,task,clin
Dim theMainWhere as String = ""
Dim theWhere As String = ""
IF (String.Compare(RProject, "-") = 0 AND String.Compare(RPhase, "-") = 0 AND String.Compare(RTask, "-") = 0 AND String.Compare(RClin, "-") = 0) THEN
'dates only
theMainWhere = theMainWhere
ELSEIF (String.Compare(RProject, "-") = 0 AND String.Compare(RPhase, "-") = 0 AND String.Compare(RTask, "-") = 0 AND String.Compare(RClin, "-") <> 0) THEN
'query = clin and dates
theMainWhere = theMainWhere & "clin.clin = '" & RClinV & "' AND "
ELSEIF (String.Compare(RProject, "-") <> 0 AND String.Compare(RPhase, "-") = 0 AND String.Compare(RTask, "-") = 0 AND String.Compare(RClin, "-") = 0) THEN
'query = project and dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND "
ELSEIF (String.Compare(RProjectV, "-") <> 0 AND String.Compare(RPhaseV, "-") = 0 AND String.Compare(RTaskV, "-") = 0 AND String.Compare(RClinV, "-") <> 0) THEN
'query = project and clin and dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND clin.clin = '" & RClinV & "' AND "
ELSEIF (String.Compare(RProjectV, "-") <> 0 AND String.Compare(RPhaseV, "-") <> 0 AND String.Compare(RTaskV, "-") = 0 AND String.Compare(RClinV, "-") = 0) THEN
'query = project and phase and dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND task.PhaseID = '" & RPhaseV & "' AND "
ELSEIF (String.Compare(RProjectV, "-") <> 0 AND String.Compare(RPhaseV, "-") <> 0 AND String.Compare(RTaskV, "-") = 0 AND String.Compare(RClinV, "-") <> 0) THEN
'query = project, phase, clin, dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND task.PhaseID = '" & RPhaseV & "' AND clin.clin = '" & RClinV & "' AND "
ELSEIF (String.Compare(RProjectV, "-") <> 0 AND String.Compare(RPhaseV, "-") <> 0 AND String.Compare(RClinV, "-") = 0 AND String.Compare(RTaskV, "-") <> 0) THEN
'query = project, phase, task, dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND task.PhaseID = '" & RPhaseV & "' AND task.TaskID = '" & RTaskV & "' AND "
ELSEIF (String.Compare(RProjectV, "-") <> 0 AND String.Compare(RPhaseV, "-") <> 0 AND String.Compare(RClinV, "-") <> 0 AND String.Compare(RTaskV, "-") <> 0) THEN
'query = project, phase, task, clin ,dates
theMainWhere = theMainWhere & "task.ProjectID = '" & RProjectV & "' AND task.PhaseID = '" & RPhaseV & "' AND task.TaskID = '" & RTaskV & "' AND clin.clin = '" & RClinV & "' AND "
END IF
theWhere = theMainWhere
session("theWhere") = theWhere
if dropemployee.selectedindex = 0 and dropproject.selectedindex = 0 then
labelid.forecolor = system.drawing.color.red
labelid.text = "Error: Must choose at least an Employee OR a Project before continuing."
else
BindDataGrid()
end if
End Sub
Bind Data Grid Sub
Code:
Sub BindDataGrid ()
If dropEmployee.selectedindex <> 0 then
EmpID = dropEmployee.SelectedItem.Value
End If
session("lastsortitem") = session("sortitem")
IF (session("lastsortitem") = session("sortitem")) THEN
IF (session("sortdirection") = "ASC") THEN
session("sortdirection") = "DESC"
ELSE
session("sortdirection") = "ASC"
END IF
END IF
strSortField = session("sortitem")
Dim strSortDirection = session("sortdirection")
Dim theDate
Dim startdate
Dim enddate
If ddday1.selectedindex = 0 or ddday1.selectedvalue = Nothing or ddday2.selectedvalue = Nothing or ddday2.selectedindex = 0 then
theDate = session("theselecteddate")
startdate = DateValue(Month(theDate) & " 1," & Year(theDate))
enddate = DateValue(Month(theDate) & " 1," & Year(theDate)).AddDays(System.DateTime.DaysInMonth(Year(theDate), Month(theDate))-1)
Else
startdate = session("theselecteddate1")
enddate = session("theselecteddate2")
End If
if dropemployee.selectedindex <> 0 then
session("dropemp") = "yes"
cmdSelect = New SqlCommand( "Select distinct rec_num, username, Hours.EmpID, wdate, whours, projectname, projectid, phasename, phaseid, taskname, taskid, Hours.taskkey, clin.clindesc, comment, complete, cooked From Clin JOIN Hours ON Clin.Clin = Hours.Clin JOIN Task ON Hours.TaskKey = Task.TaskKey JOIN Employee ON Hours.EmpID = Employee.EmpID where " & session("theWhere") & "Hours.EmpID='" & EmpID & "' and hours.wdate between '" & startdate & "' and '" & enddate & "' order by " & strSortField &" " & strSortDirection &"", sqlconn )
else
session("dropemp") = "no"
cmdSelect = New SqlCommand( "Select distinct rec_num, username, Hours.EmpID, wdate, whours, projectname, projectid, phasename, phaseid, taskname, taskid, Hours.taskkey, clin.clindesc, comment, complete, cooked From Clin JOIN Hours ON Clin.Clin = Hours.Clin JOIN Task ON Hours.TaskKey = Task.TaskKey JOIN Employee ON Hours.EmpID = Employee.EmpID where " & session("theWhere") & "hours.wdate between '" & startdate & "' and '" & enddate & "' order by " & strSortField &" " & strSortDirection &"", sqlconn )
end if
sqlconn.Open()
dispreport.DataSource = cmdSelect.ExecuteReader()
dispreport.DataBind()
sqlconn.Close()
End Sub
Click Processing Sub
Code:
Sub ClickProcessing()
session("clickproc") = 1
ReportShow = 0
dispreport.visible = false
' RIDNUM = Session("RIDNUM")
RIDNUM = -1
Session("RIDNUM") = RIDNUM
Instructions.visible = false
IBBulkEdit.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to Bulk Edit multiple rows/items?')")
' IBAdminLock.Attributes.Add("onClick", "javascript:return confirm('Are you sure you want to Bulk Admin Lock entire selected month?')")
Dim CurrentHoursRecord = New Hour()
sqlconn = New SqlConnection( "Server=wattsbilprod;UID=pims2;PWD=pims2;Database=PIMS2" )
DIM IDCapture as SqlDataReader
sqlconn.Open()
cmdSelect = New SqlCommand( "Select EmpID, FirstName, LastName From employee where DomainUser ='" & user.identity.name & "'", sqlconn )
IDCapture = cmdSelect.ExecuteReader()
While IDcapture.read()
AdminEmpID=IDcapture( "EmpID" )
FirstName=idcapture("FirstName")
LastName=idcapture("LastName")
End while
sqlconn.Close()
'Check For God Rights Here Else Exit
Session("adminName") = FirstName & " " & LastName
Session("AdminEmpID") = AdminEmpID
Session("Identity") = FirstName & " " & LastName
Session("AdminUser.EmpID") = AdminEmpID
Session("CurrentHour") = New Hour()
Session("CurrentEmployee") = New Employee()
sqlconn.Open()
' Dim Empchoice As SqlDataReader
' cmdSelect = New SqlCommand( "select (lastname + ', ' + firstname) as UserName, EmpID from Employee order by UserName asc" , sqlconn )
' Empchoice = cmdSelect.ExecuteReader()
' dropemployee.DataSource = Empchoice
' dropemployee.DataTextField = "UserName"
' dropemployee.datavaluefield = "EmpID"
' dropemployee.DataBind()
' Empchoice.Close()
' dropemployee.items.insert(0, "-")
' dropemployee.selectedvalue = EmpID
If dropEmployee.selectedindex <> 0 then
EmpID = dropEmployee.SelectedItem.Value
Dim Clinchoice As SqlDataReader
' sqlconn.Open()
cmdSelect = New SqlCommand( "select distinct Clin.clin, (convert(varchar, clin.clin) + ' - ' + clindesc) as clindesc from clin JOIN ClinEmp ON Clin.Clin = ClinEmp.Clin JOIN Employee ON Employee.EmpID = ClinEmp.EmpID where ClinEmp.EmpID = '" & EmpID & "' order by ClinDesc asc" , sqlconn )
Clinchoice = cmdSelect.ExecuteReader()
dropClin.DataSource = Clinchoice
dropClin.DataTextField = "ClinDesc"
dropClin.DataValueField = "Clin"
dropClin.DataBind()
Clinchoice.Close()
' sqlconn.Close()
dropClin.items.insert(0, "-" )
else
dropclin.items.clear()
dropclin.items.insert(0, "-")
end if
Dim Projectchoice As SqlDataReader
cmdSelect = New SqlCommand( "select distinct ProjectID, (convert(varchar, projectid) + ' - ' + projectname) as ProjectName FROM task where ProjectActive = 'Y' order by ProjectName asc" , sqlconn )
Projectchoice = cmdSelect.ExecuteReader()
dropproject.DataSource = Projectchoice
dropproject.DataTextField = "ProjectName"
dropproject.datavaluefield = "ProjectID"
dropproject.DataBind()
Projectchoice.Close()
sqlconn.Close()
if not dropproject.items(0) Is "-" then
dropproject.items.insert(0, "-")
end If
' labelid.text = ""
dropproject.selectedindex = 0
dropphase.items.clear()
dropphase.items.insert(0, "-")
droptask.items.clear()
droptask.items.insert(0, "-")
texthours.text = ""
textcomments.text = ""
cbdeleted.checked = false
ibsave.visible = true
ibdelete.visible = false
ibupdate.visible = false
ibcancel.visible = false
ibbulkedit.visible = true
ibadminlock.visible = true
' Dim theselecteddate As DateTime = ddmonth.selecteditem.value & "/1/" & ddyear.selecteditem.value
' session("theselecteddate") = theselecteddate
Session("sortitem") = "Rec_num"
Session("lastsortitem") = "Rec_num"
Session("sortdirection") = "ASC"
' BindDataGrid()
End Sub
If it's too much, I guess I can upload it somewhere in a text file if you want. Thanks for the help.
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
what I would try is replacing this line
response.Redirect("limitedgodentry.aspx") - update button sub
with
BindDataGrid()
it has been my experience that when ever I update a record and then want to have that view updated on the page i need to rebind the data to the datagrid
No, I guess I wasn't clear enough. The only time I want to databind is when the user hits the Show Data button. Right after just about any other action, I want the ClickProcessing sub to be called which handles everything. The response.redirect is only in there right now for temporary purposes so that the thing works, but it's a hassle as it 'should' work with just going to the ClickProcessing sub. I don't want to databind right after the update because of other things I have going on. I want the clickprocessing sub to do kind of a 'clean up', reset/clear a few things, including the datagrid, and then force the user to click on the Show Data button again to do the real databind which queries the DB and whatnot. Meaning that all of the functions that call ClickProcessing work, EXCEPT for the Delete and Update buttons, and this is my whole dilema. I just can't see why it's not working and why it's creating those empty drowdownlists in the edited row. Do you understand now? :-)
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
i have a better idea but i have never relied on another sub to do something other than data binding which i have always called after any sql command. most databinds do not do anything other than requery the dbase and bind it. it should not be affecting other things, but apperently it will not work for you. there is nothing in the code jumping out at me so i dont know...
Yes, that's why it's so strange. I do the DataBind right after the Query but I also do the DataBind with the Show Data button. Either way, it still doesn't work, which is why I'm puzzled beyond belief. And it's not related to any specific piece of data as it doesn't matter what data I choose to display, that same row will not have anything in the dropdownlists. It's so strange I just don't know where to continue after this, other than just leaving the response.redirects in there. But with those, as I said before, I lose what data was chosen to begin with which is extremely inconvenient. I'll try to see what I can find out later, if anything, and post my results. Thanks anyway.
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein
Well, I figured out something else about this issue. This not only happens when I hit the Update and Delete buttons, but also when I hit the Show Data button. Remember this is only if the Edit button (selecting a single row in the datagrid to edit) is pressed. So, I don't think it has anything to do with the Update, Delete, or Show Data buttons at all, but rather the ItemDataBound sub or the BindDataGrid sub, I'm not sure which one. Does this help anyone with their knowledge on this? Thanks for any help that you may give. :-)
__________________ LittlBUGer.info
"Only two things are infinite, the universe and human stupidity, and I'm not sure about the former." -- Albert Einstein