I have a GridView as below:
<asp:GridView ID="gvChain" runat="server" Font-Size="Small" CellPadding="3" CellSpacing="1" GridLines="None"
AutoGenerateColumns="False">
<HeaderStyle BackColor="#CCCCCC" />
<Columns>
<asp:TemplateField HeaderText="Department" ControlStyle-Width="175px">
<EditItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</EditItemTemplate>
<ItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Text='<%# Bind("Department") %>'></asp:Label>
</ItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Manager Level 1" ControlStyle-Width="175px">
<ItemTemplate>
<asp:Label ID="lblManager1" runat="server" Text=""></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager1" runat="server"></asp:DropDownList>
</EditItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Manager Level 2" ControlStyle-Width="175px">
<ItemTemplate>
<asp:Label ID="lblManager2" runat="server" Text=""></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager2" runat="server"></asp:DropDownList>
</EditItemTemplate>
<ControlStyle Width="175px" />
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnEdit" CommandName="Edit" runat="server" Text="Edit" CssClass="buttonStyle" CausesValidation="false"/>
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="btnSave" CommandName="Update" runat="server" Text="Save" CssClass="buttonStyle" CausesValidation="false"/>
<asp:LinkButton ID="btnCancel" CommandName="Cancel" runat="server" Text="Cancel" CssClass="buttonStyle" CausesValidation="false" />
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:LinkButton ID="btnDelete" CommandName="Delete" runat="server" Text="Delete" CssClass="buttonStyle" CausesValidation="false" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
The BoundField is populated in the Page_Load event as below:
Dim dHandler As DepartmentHandler = New DepartmentHandler
Dim depts As New List(Of Department)
depts = dHandler.GetDepartmentList
gvChain.DataSource = depts.
If Not Page.IsPostBack Then
gvChain.DataBind()
End If
Populating of the TemplateFields is then done in the RowDataBound event as below:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState = DataControlRowState.Edit Then
Dim cbManager1 As DropDownList = TryCast(e.Row.FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(e.Row.FindControl("cbManager2"), DropDownList)
Dim eHandler As EmployeeHandler = New EmployeeHandler
' Get the list of managers
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
cbManager1.DataSource = mgrs
cbManager2.DataSource = mgrs
cbManager1.DataValueField = "Name"
cbManager1.DataTextField = "Name"
cbManager2.DataValueField = "Name"
cbManager2.DataValueField = "Name"
cbManager1.DataBind()
cbManager2.DataBind()
' Get the department name from the label in cell 0
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
' Pass the department name to the getManager1/2 functions to return the correct manager for that department
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
' Upper case the manager name to search the DDLs for item
Dim mgr1Name As String = mgr1.Name.ToUpper()
Dim mgr2Name As String = mgr2.Name.ToUpper()
' Find the manager in the DDL and select
cbManager1.SelectedValue = mgr1Name
cbManager2.SelectedValue = mgr2Name
Else
' If GV isnt in edit mode then populate labels in itemtemplate with manager 1 and 2 values
Dim lblManager1 As Label = DirectCast(e.Row.FindControl("lblManager1"), Label)
Dim lblManager2 As Label = DirectCast(e.Row.FindControl("lblManager2"), Label)
Dim eHandler As EmployeeHandler = New EmployeeHandler
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
lblManager1.Text = mgr1.Name
lblManager2.Text = mgr2.Name
End If
End If
I then have the below in the RowEditing event
gvChain.EditIndex = e.NewEditIndex
gvChain.DataBind()
When there is only 1 record displayed in the GridView, I click the edit button and the GridView goes into Edit mode I am able to update that record using the RowUpdating event and this works fine. However, if I add another record to the GridView, clicking on the edit button of that record gives a NullReference exception. If I then add another record, that 3rd record will go into edit mode. A 4th record will again fail with a NullReference exception and so on.
When debugging, it seems that on rows indexes 1,3,5 etc. the GridView doesn't go into edit mode however on row indexes 0, 2, 4 etc. the GridView will switch to edit mode.
This seems really strange behaviour. Any ideas what may be causing the GridView not to go into Edit mode on these rows?
A row's state can be one or a combination of the DataControlRowState values, so use bitwise operations to determine whether the state of the row includes a DataControlRowState value.
here
RowState contains more than one value (Alternate | Edit if you check RowState property during edit mode) using bit-logic.
Try
If (e.Row.RowState And DataControlRowState.Edit) > 0 Then
I got round this by amending the getDepartmentList function to return the Manager1 and Manager 2 fields then databinding them in the same was as I had bound 'Department'.
I then amended the RowDataBound event to the following:
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowState And DataControlRowState.Edit Then
Dim cbManager1 As DropDownList = TryCast(e.Row.FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(e.Row.FindControl("cbManager2"), DropDownList)
Dim eHandler As EmployeeHandler = New EmployeeHandler
' Get the list of managers
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
cbManager1.DataSource = mgrs
cbManager2.DataSource = mgrs
cbManager1.DataValueField = "Name"
cbManager1.DataTextField = "Name"
cbManager2.DataValueField = "Name"
cbManager2.DataValueField = "Name"
cbManager1.DataBind()
cbManager2.DataBind()
' Get the department name from the label in cell 0
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
' Pass the department name to the getManager1/2 functions to return the correct manager for that department
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
' Upper case the manager name to search the DDLs for item
Dim mgr1Name As String = mgr1.Name.ToUpper()
Dim mgr2Name As String = mgr2.Name.ToUpper()
' Find the manager in the DDL and select
cbManager1.SelectedValue = mgr1Name
cbManager2.SelectedValue = mgr2Name
End If
End If
Related
In a detailsview I have a drop down list whose selection determines the list in a second Drop down list. When the web page loads all my "Get Data" Functions load the various Drop down boxes. After I make a selection in the first of the two related drop down boxes I call an "index changed" function that takes the value of the first drop down box, as a variable, and puts it into a SQL statement. This SQL statement runs correctly inside SQL. However, the second drop down doesn't reload with the new data the values in the second drop down remain the same. Here is the pertinent code:
` <asp:TemplateField HeaderText="Planting Hatchery">
<ItemTemplate>
<asp:Label ID="lblPlantHatch" runat="server" Text='<%# Eval ("HatcheryCodePlant")%>' Visible = "true"></asp:Label>
</ItemTemplate>
<insertItemTemplate>
<asp:DropDownList ID="ddPlantingHatchery" runat="server" DataSource='<%# GetPlantingHatchery()%>'DataTextField="HatcheryNamePlant" DataValueField="HatcheryCodePlant" width= "150" AppendDataBoundItems="true" AutoPostBack="true"
OnSelectedIndexChanged="ddPlantingHatchery_indexchanged">
<asp:ListItem Text="Select" Value="" />
</asp:DropDownList>
</insertItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Water Body Name">
<ItemTemplate>
<asp:Label ID="lblStreamName" runat="server" Text='<%# Eval("CatalogNo")%>' Visible = "true"></asp:Label>
</ItemTemplate>
<insertItemTemplate>
<asp:DropDownList ID="ddCatalogName" runat="server" DataSource='<%# GetCatalogNames()%>'
DataTextField="StreamName" DataValueField="CatalogNo" AppendDataBoundItems="true" >
<asp:ListItem Text="Select" Value="" />
</asp:DropDownList>
<asp:ObjectDataSource ID="dsWaterBody" runat="server" TypeName="StreamName"
<SelectMethod="GetCatalogNames">
<SelectParameters>
<asp:ControlParameter Name="HatcheryCodePlant" Type="string" ControlID="ddPlantingHatchery" PropertyName="Selectedvalue"/>
</SelectParameters>
</asp:ObjectDataSource>
</insertItemTemplate>`
This is the Code Behind:`
Public Function GetPlantingHatchery() As DataSet
Dim myConnection As New SqlConnection(ConnectionString)
Dim ad As New SqlDataAdapter("SELECT HatcheryNamePlant, HatcheryCodePlant FROM HatcheryPlant Order by HatcheryNamePlant", myConnection)
Dim ds As New DataSet()
ad.Fill(ds, "HatcheryPlant")
Return ds
End Function
Public Function GetCatalogNames() As DataSet
Dim myConnection As New SqlConnection(ConnectionString)
Dim ad As New SqlDataAdapter("SELECT StreamName, CatalogNo, HatcheryNamePlant, HatcheryCodePlant, LLID FROM vwStockingWatersByHatchery Order By StreamName", myConnection)
Dim dsWaterBody As New DataSet()
ad.Fill(dsWaterBody, "Catalog")
Return dsWaterBody
End Function
Public Function ddPlantingHatchery_indexchanged(sender As Object, e As EventArgs)
Try
Dim ddCatNum As DropDownList = TryCast(dvSMasterCurrentYear.FindControl("ddCatalogName"), DropDownList)
'ddCatNum.SelectedValue = TryCast(dvSMasterCurrentYear.FindControl("ddPlantingHatchery"), DropDownList).SelectedValue
MySelectedValue = TryCast(dvSMasterCurrentYear.FindControl("ddPlantingHatchery"), DropDownList).SelectedValue
Dim myConnection As New SqlConnection(ConnectionString)
Dim ad As New SqlDataAdapter("SELECT StreamName, CatalogNo, HatcheryNamePlant, HatcheryCodePlant, LLID FROM vwStockingWatersByHatchery where HatcheryCodePlant = '" + MySelectedValue + "' Order By StreamName", myConnection)
Dim dsWaterBody As New DataSet()
ad.Fill(dsWaterBody, "Catalog")
Return dsWaterBody
Catch ex As Exception
End Try`
What do I need to do to load the second Drop down list with the new data?
I am having a lot of trouble getting a dropdown to bind with data from my database with the appropriate departments.
This is what I have so far:
HTML:
<asp:GridView ID="gridDepartmentHistory" runat="server" AutoGenerateColumns="False" AutoGenerateDeleteButton="True" AutoGenerateEditButton="True">
<Columns>
<asp:TemplateField HeaderText="Department">
<ItemTemplate>
<asp:Label ID="lblDepartment" runat="server" Visible="true" Text='<%# Eval("Department")%>'></asp:Label>
<asp:DropDownList ID="ddlDepartment" runat="server">
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="Start Date" HeaderText="Start Date" />
<asp:BoundField DataField="End Date" HeaderText="End Date" />
</Columns>
</asp:GridView>
Code behind:
Protected Sub gridDepartmentHistory_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles gridDepartmentHistory.RowDataBound
If (e.Row.RowType = DataControlRowType.DataRow) Then
Dim ddlDepartment As DropDownList = CType(e.Row.FindControl("ddlDepartment"), DropDownList)
Dim list As ICollection(Of Department) = Department.hrGetDepartmentList() 'Class method to fill a collection of items with the Department's Name and ID
ddlDepartment.DataSource = list
ddlDepartment.DataTextField = "Name"
ddlDepartment.DataValueField = "ID"
ddlDepartment.DataBind()
Dim dept As String = CType(e.Row.FindControl("lblDepartment"), Label).Text
ddlDepartment.Items.FindByText(dept).Selected = True
End If
End Sub
When I run this it throws an exception saying:
Object reference not set to an instance of an object.
BTW: I am using this tutorial to help me through: http://www.aspsnippets.com/Articles/How-to-populate-DropDownList-in-GridView-in-ASPNet.aspx
Any help would be greatly appreciated! Thank you!
You simply need to retrieve dept id and store it in gridview as hidden (if you don't want to display it).
Dim dept As String = CType(e.Row.FindControl("lblDepartmentId"), Label).Text
ddlDepartment.SelectedValue = dept;
Hope it helps.
Your problem is that you ara trying to find the contorl in the row but is inside a table cell.
Try this.
Dim cbo As DropDownList = CType(YourDGV.Rows(x).Cells(0).FindControl("ddlDepartment"), DropDownList)
I'm using Visual Basic with ASP.NET. I have a GridView table with a DroDownList column and I need a way to get the selected item from it. Now I'm using an ImageButton in order to get the selected item from the DropDownList to pop-up as a message box. I already know how to get an integer from a boundfield. However, using the same code to get the DropDownList item won't work.
This is a snippet from my code:
ASP code:
<asp:BoundField DataField="Case#" HeaderText="Case#" ReadOnly="True" />
<asp:TemplateField HeaderText="Surgery Time">
<ItemTemplate>
<asp:DropDownList ID="Time_Slot" runat ="server">
<asp:ListItem Selected="True" Value="0">Select...</asp:ListItem>
<asp:ListItem Value="1">8:00</asp:ListItem>
<asp:ListItem Value="2">9:00</asp:ListItem>
<asp:ListItem Value="3">10:00</asp:ListItem>
<asp:ListItem Value="4">11:00</asp:ListItem>
<asp:ListItem Value="5">12:00</asp:ListItem>
<asp:ListItem Value="6">1:00</asp:ListItem>
<asp:ListItem Value="7">2:00</asp:ListItem>
<asp:ListItem Value="8">3:00</asp:ListItem>
<asp:ListItem Value="9">4:00</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:ButtonField buttontype="Image" ImageUrl="~/Images/check.jpg" commandname="Accept" HeaderText="Accept" SortExpression="Accept" />
Visual Basic code:
Sub GridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
If e.CommandName = "Accept" Then
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
Dim selectedRow As GridViewRow = GridView1.Rows(index)
'This value is retrieved from the databound
Dim contactCell As TableCell = selectedRow.Cells(0)
Dim contact As String = contactCell.Text
'however here it is not retrieved from the dropdownlist
Dim contactCell2 As TableCell = selectedRow.Cells(1)
Dim contact2 As String = contactCell2.Text
MsgBox("case number is" + contact + "time is" + contact2)
End If
End Sub
Try this.
If e.CommandName = "Accept" Then
Dim index = e.CommandArgument
Dim timeSlot = CType(gridview1.Rows(index).FindControl("Time_Slot"), DropDownList)
Dim selectedTimeSlot = timeSlot.SelectedValue
End If
In a DetailsView I have set visible = false for a TemplateField with HeaderText of "No Treatment Reason:".
In the code behind how can I reference the DataRow explicitly and make it visible based on the value of the other TemplateField with the HeaderText of "Care Plan Intent:" ?
<asp:DetailsView ID="dvTest" FooterStyle-Width="100%" Font-Bold="false" BackColor="#A2C4EA"
FieldHeaderStyle-Width="35%" BorderWidth="1" CellSpacing="2" Font-Names="Arial, Helvetica, sans-serif"
Font-Size="12px" runat="server" AutoGenerateRows="False" AllowPaging="False" style="width:98%"
HeaderStyle-BackColor="White" HeaderStyle-Font-Bold="true" HeaderStyle-HorizontalAlign="center">
<Fields>
<asp:TemplateField HeaderText="Care Plan Intent:">
<ItemTemplate>
<asp:Label skinid="tablabelblack" id="lblIntent" runat="server" Text='<%# Eval("CarePlanIntent") %>' />
<asp:HiddenField runat="server" ID="hidCarePlanIntent" Value='<%# Eval("CarePlanIntent") %>' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="No Treatment Reason:" Visible="false">
<ItemTemplate>
<asp:Label skinid="tablabelblack" id="lblNoTreatmentReason" runat="server" Text='<%# Eval("NoTreatmentReason") %>' />
</ItemTemplate>
</asp:TemplateField>
</Fields>
</asp:DetailsView>
You have to use the DataBound event and cast the DataItem to the correct type (f.e. DataRowView). You can use FindControl to get your controls and following LINQ query to get the correct column to make it (in)visible:
protected void dvTest_DataBound(Object sender, EventArgs e)
{
var noTreatCol = this.dvTest.Fields.Cast<DataControlField>()
.First(field => field.HeaderText == "No Treatment Reason:");
DataRow row = ((DataRowView) dvTest.DataItem).Row;
Label tablabelblack = (Label)dvTest.FindControl("tablabelblack");
HiddenField hidCarePlanIntent = (HiddenField)dvTest.FindControl("hidCarePlanIntent");
string value = row.Field<string>("Value"); // just an example
noTreatCol.Visible = value == "SomeValueThatMakesItVisible";
}
Is it possible to do that in VB and without LINQ?
Of course:
Protected Sub dvTest_DataBound(sender As Object, e As EventArgs)
Dim row As DataRow = DirectCast(dvTest.DataItem, DataRowView).Row
Dim tablabelblack As Label = DirectCast(dvTest.FindControl("tablabelblack"), Label)
Dim hidCarePlanIntent As HiddenField = DirectCast(dvTest.FindControl("hidCarePlanIntent"), HiddenField)
Dim value As String = row.Field(Of String)("Value") ' just an example '
Dim noTreatColIndex As Int32 = -1
For i As Int32 = 0 To Me.dvTest.Fields.Count - 1
Dim field = dvTest.Fields(i)
If field.HeaderText = "No Treatment Reason:" Then
noTreatColIndex = i
Exit For
End If
Next
If noTreatColIndex > -1 Then
dvTest.Fields(noTreatColIndex).Visible = value = "SomeValueThatMakesItVisible"
End If
End Sub
I have a GridView as below
<asp:GridView ID="gvChain" runat="server" Font-Size="Small" CellPadding="3" CellSpacing="1" GridLines="None" AutoGenerateColumns="False">
<headerstyle backcolor="#CCCCCC" />
<columns>
<asp:BoundField DataField="Department" HeaderText="Department" />
<asp:TemplateField HeaderText="Manager Level 1">
<ItemTemplate>
<asp:Label ID="lblManager1" runat="server" Text=""></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager1" runat="server"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Manager Level 2">
<ItemTemplate>
<asp:Label ID="lblManager2" runat="server"/>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList ID="cbManager2" runat="server"/>
</EditItemTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="True">
<ControlStyle ForeColor="#009EDD" />
</asp:CommandField>
</columns>
</asp:GridView>
The BoundField 'Department' is being populated in the Page_Load as below which works fine and populates the GridView with a list of departments.
Dim dhandler As DepartmentHandler = New DepartmentHandler
Dim depts As New List(Of Department)
depts = dhandler.GetDepartmentList
gvChain.DataSource = depts
gvChain.DataBind()
I am then populating the ItemTemplates of the TemplateFields in the RowDAtaBound event as below. this is also working fine.
If e.Row.RowType = DataControlRowType.DataRow Then
Dim lblManager1 As Label = DirectCast(e.Row.FindControl("lblManager1"), Label)
Dim lblManager2 As Label = DirectCast(e.Row.FindControl("lblManager2"), Label)
Dim eHandler As EmployeeHandler = New EmployeeHandler
Dim deptCell As TableCell = e.Row.Cells(0)
Dim dept As Department = New Department
dept.Department = deptCell.Text
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
lblManager1.Text = mgr1.Name
lblManager2.Text = mgr2.Name
End If
What I now want to achieve is when clicking on the 'Edit' field of a row on the GridView, populate cbManager1 and cbManager2 with a list of Managers and set the SelectedValue of each DDL to the same values as I am retrieving in the item template. I can get the data with the below code in the RowEditing event of the GridView:
' Get the list of managers
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
' Get the department name from the BoundField
Dim deptCell As TableCell = gvChain.Rows(e.NewEditIndex).Cells(0)
Dim dept As Department = New Department
dept.Department = deptCell.Text
' Pass the department name to the getManager1/2 functions to return the correct manager for that department
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
I have set breakpoints to check the data is being returned from the functions and the data is there as expected but where I am stuck is getting a reference on the DDLs in the EditItemTemplate so I can databind them and set the SelectedValue.
I have tried the below but this is giving a NullReference Exception:
Dim cbManager1 As DropDownList = TryCast(gvChain.Rows(e.NewEditIndex).FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(gvChain.Rows(e.NewEditIndex).FindControl("cbManager2"), DropDownList)
I got round this in the end. I added the following code to the RowEditing event
gvChain.EditIndex = e.NewEditIndex
gvChain.DataBind()
I then did the following in the RowDataBound event
If e.Row.RowState = DataControlRowState.Edit Then
Dim cbManager1 As DropDownList = TryCast(e.Row.FindControl("cbManager1"), DropDownList)
Dim cbManager2 As DropDownList = TryCast(e.Row.FindControl("cbManager2"), DropDownList)
Dim eHandler As EmployeeHandler = New EmployeeHandler
Dim mgrs As New List(Of Manager)
mgrs = eHandler.GetManagerList
cbManager1.DataSource = mgrs
cbManager2.DataSource = mgrs
cbManager1.DataValueField = "Name"
cbManager1.DataTextField = "Name"
cbManager2.DataValueField = "Name"
cbManager2.DataValueField = "Name"
cbManager1.DataBind()
cbManager2.DataBind()
' Got rid of the bound field in the end and did it with a templatefield so needed to get the department from the label
Dim lbl As Label = e.Row.Cells(0).FindControl("lblDepartment")
Dim dept As Department = New Department
dept.Department = lbl.Text
Dim mgr1 As Manager = eHandler.getManager1(dept)
Dim mgr2 As Manager = eHandler.getManager2(dept)
Dim mgr1Name As String = mgr1.Name.ToUpper()
Dim mgr2Name As String = mgr2.Name.ToUpper()
cbManager1.SelectedValue = mgr1Name
cbManager2.SelectedValue = mgr2Name
End If
You could try something like this
If e.Row.RowState = DataControlRowState.Edit Then
Dim cbmanager As DropDownList = e.Row.FindControl("cbmanager1")
If Not cbmanager Is Nothing Then cbmanager.Items.Add(New ListItem("Test1", "Test1"))
End If