javagair
asked on
why does hiding label and calling dropdownlist make all of listitems go blank
dropdownlist are filled from the same table which is only used to fill 4 dropdownlists. The values selected are stored in another table by soc sec. number. I want the users to see what they selected the last time they edited their time sheet.
the first dropdownlist (this one shows numbers) has all of the numbers for a 24 hour clock; but I want to show what the previous choosen value was rather than starting with 0:00
I tried adding a label in the second dropdownlist then hiding it and showing the dropdownlist. Problem here is that now the list is empty.
Did I miss something with the label? or is there a way of of reading the time sheet and choosing that same item in the drop down list and showing it as the starting value for the dropdownlist? Example the default time to start work is 8:00, this shows up in the dropdownlist with the label in the label; is there a way to show 8:00 when going to edit mode instead of 0:00?
I would sooner the dropdownlist show the correct time without using the labels, but at this point any solution that works would be acceptable.
haven't written code to write selection back to other table yet.
suggestions?
gary
<asp:TemplateField HeaderText="IN">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OUT">
<ItemTemplate>
<asp:Label ID="lblout" runat="server" Text='<%# Eval("EndTime")%>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblout" runat="server" Text='<%# Bind("EndTime")%>' Visible = "False"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" >
</asp:DropDownList>
</editItemTemplate>
</asp:TemplateField>
Sub CustomersGridView_RowDataB ound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
Dim sqlfindhrsfill As String
If e.Row.RowType = DataControlRowType.DataRow Then
Try
sqlfindhrsfill = "Select JobCode from testday "
Using adapter8 As SqlDataAdapter = New SqlDataAdapter(sqlfindhrsf ill, Connection)
Connection.Open()
adapter8.Fill(Dst, "Dsthrslist")
Dim ddl1 = DirectCast(e.Row.FindContr ol("DropDo wnlist1"), DropDownList)
ddl1.DataSource = Dst.Tables("DsthrsList")
ddl1.DataTextField = "Jobcode"
ddl1.DataValueField = "JobCode"
'ddl1.SelectedValue = '<%# Bind("Starttime") %>'
ddl1.DataBind()
Dim ddl2 = DirectCast(e.Row.FindContr ol("DropDo wnlist2"), DropDownList)
ddl2.DataSource = Dst.Tables("DsthrsList")
ddl2.DataTextField = "Jobcode"
ddl2.DataValueField = "JobCode"
ddl2.DataBind()
Dim ddl3 = DirectCast(e.Row.FindContr ol("DropDo wnlist3"), DropDownList)
ddl3.DataSource = Dst.Tables("DsthrsList")
ddl3.DataTextField = "Jobcode"
ddl3.DataValueField = "JobCode"
ddl3.DataBind()
Dim ddl4 = DirectCast(e.Row.FindContr ol("DropDo wnlist4"), DropDownList)
ddl4.DataSource = Dst.Tables("DsthrsList")
ddl4.DataTextField = "Jobcode"
ddl4.DataValueField = "JobCode"
ddl4.DataBind()
End Using
Catch
End Try
Connection.Close()
End If
End Sub
the first dropdownlist (this one shows numbers) has all of the numbers for a 24 hour clock; but I want to show what the previous choosen value was rather than starting with 0:00
I tried adding a label in the second dropdownlist then hiding it and showing the dropdownlist. Problem here is that now the list is empty.
Did I miss something with the label? or is there a way of of reading the time sheet and choosing that same item in the drop down list and showing it as the starting value for the dropdownlist? Example the default time to start work is 8:00, this shows up in the dropdownlist with the label in the label; is there a way to show 8:00 when going to edit mode instead of 0:00?
I would sooner the dropdownlist show the correct time without using the labels, but at this point any solution that works would be acceptable.
haven't written code to write selection back to other table yet.
suggestions?
gary
<asp:TemplateField HeaderText="IN">
<ItemTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" >
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="OUT">
<ItemTemplate>
<asp:Label ID="lblout" runat="server" Text='<%# Eval("EndTime")%>' ></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Label ID="lblout" runat="server" Text='<%# Bind("EndTime")%>' Visible = "False"></asp:Label>
<asp:DropDownList ID="DropDownList2" runat="server" >
</asp:DropDownList>
</editItemTemplate>
</asp:TemplateField>
Sub CustomersGridView_RowDataB
Dim sqlfindhrsfill As String
If e.Row.RowType = DataControlRowType.DataRow
Try
sqlfindhrsfill = "Select JobCode from testday "
Using adapter8 As SqlDataAdapter = New SqlDataAdapter(sqlfindhrsf
Connection.Open()
adapter8.Fill(Dst, "Dsthrslist")
Dim ddl1 = DirectCast(e.Row.FindContr
ddl1.DataSource = Dst.Tables("DsthrsList")
ddl1.DataTextField = "Jobcode"
ddl1.DataValueField = "JobCode"
'ddl1.SelectedValue = '<%# Bind("Starttime") %>'
ddl1.DataBind()
Dim ddl2 = DirectCast(e.Row.FindContr
ddl2.DataSource = Dst.Tables("DsthrsList")
ddl2.DataTextField = "Jobcode"
ddl2.DataValueField = "JobCode"
ddl2.DataBind()
Dim ddl3 = DirectCast(e.Row.FindContr
ddl3.DataSource = Dst.Tables("DsthrsList")
ddl3.DataTextField = "Jobcode"
ddl3.DataValueField = "JobCode"
ddl3.DataBind()
Dim ddl4 = DirectCast(e.Row.FindContr
ddl4.DataSource = Dst.Tables("DsthrsList")
ddl4.DataTextField = "Jobcode"
ddl4.DataValueField = "JobCode"
ddl4.DataBind()
End Using
Catch
End Try
Connection.Close()
End If
End Sub
ASKER
adding code causes this error
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
Failed to load viewstate. The control tree into which viewstate is being loaded must match the control tree that was used to save viewstate during the previous request. For example, when adding controls dynamically, the controls added during a post-back must match the type and position of the controls added during the initial request.
ASKER
added the following code to rowedit and rowupdate
dropdownlist always shows the selection correctly for what is stored in both tables.
gary
Try
sqlfindhrsfill = "Select JobCode from testday "
Using adapter8 As SqlDataAdapter = New SqlDataAdapter(sqlfindhrsf ill, Connection)
Connection.Open()
adapter8.Fill(Dst, "Dsthrslist")
Dim ddl1 = DirectCast(CustomersGridVi ew.Rows(e. NewEditInd ex).FindCo ntrol("Dro pDownlist1 "), DropDownList)
ddl1.DataSource = Dst.Tables("DsthrsList")
ddl1.DataTextField = "Jobcode"
ddl1.DataValueField = "JobCode"
ddl1.SelectedValue = Dst.Tables("Dstaccuminfo2" ).Rows(0). Item(3).To String()
ddl1.DataBind()
Dim ddl2 = DirectCast(CustomersGridVi ew.Rows(e. NewEditInd ex).FindCo ntrol("Dro pDownlist2 "), DropDownList)
ddl2.DataSource = Dst.Tables("DsthrsList")
ddl2.DataTextField = "Jobcode"
ddl2.DataValueField = "JobCode"
ddl2.SelectedValue = Dst.Tables("Dstaccuminfo2" ).Rows(0). Item(4).To String()
ddl2.DataBind()
Dim ddl3 = DirectCast(CustomersGridVi ew.Rows(e. NewEditInd ex).FindCo ntrol("Dro pDownlist3 "), DropDownList)
ddl3.DataSource = Dst.Tables("DsthrsList")
ddl3.DataTextField = "Jobcode"
ddl3.DataValueField = "JobCode"
ddl3.SelectedValue = Dst.Tables("Dstaccuminfo2" ).Rows(0). Item(5).To String()
ddl3.DataBind()
Dim ddl4 = DirectCast(CustomersGridVi ew.Rows(e. NewEditInd ex).FindCo ntrol("Dro pDownlist4 "), DropDownList)
ddl4.DataSource = Dst.Tables("DsthrsList")
ddl4.DataTextField = "Jobcode"
ddl4.DataValueField = "JobCode"
ddl4.SelectedValue = Dst.Tables("Dstaccuminfo2" ).Rows(0). Item(6).To String()
ddl4.DataBind()
End Using
Catch
End Try
dropdownlist always shows the selection correctly for what is stored in both tables.
gary
Try
sqlfindhrsfill = "Select JobCode from testday "
Using adapter8 As SqlDataAdapter = New SqlDataAdapter(sqlfindhrsf
Connection.Open()
adapter8.Fill(Dst, "Dsthrslist")
Dim ddl1 = DirectCast(CustomersGridVi
ddl1.DataSource = Dst.Tables("DsthrsList")
ddl1.DataTextField = "Jobcode"
ddl1.DataValueField = "JobCode"
ddl1.SelectedValue = Dst.Tables("Dstaccuminfo2"
ddl1.DataBind()
Dim ddl2 = DirectCast(CustomersGridVi
ddl2.DataSource = Dst.Tables("DsthrsList")
ddl2.DataTextField = "Jobcode"
ddl2.DataValueField = "JobCode"
ddl2.SelectedValue = Dst.Tables("Dstaccuminfo2"
ddl2.DataBind()
Dim ddl3 = DirectCast(CustomersGridVi
ddl3.DataSource = Dst.Tables("DsthrsList")
ddl3.DataTextField = "Jobcode"
ddl3.DataValueField = "JobCode"
ddl3.SelectedValue = Dst.Tables("Dstaccuminfo2"
ddl3.DataBind()
Dim ddl4 = DirectCast(CustomersGridVi
ddl4.DataSource = Dst.Tables("DsthrsList")
ddl4.DataTextField = "Jobcode"
ddl4.DataValueField = "JobCode"
ddl4.SelectedValue = Dst.Tables("Dstaccuminfo2"
ddl4.DataBind()
End Using
Catch
End Try
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you are right
Too much work!
Easiest solution is to use styles to hide them and still make the values availale:
So, instead of this:
Open in new window
use this:
Open in new window
*NOW*, you hide the label but value is not hidden.