Get result items list twice

Oct 14, 2011 at 1:17 AM

Hi,

thanks for your control I've searching for a while and yours seems to fit the bill.

If I use your example using the years as datasource, no problem

However when I add a sqldatasource to the control it spits out the result list twice?

Also, the control kills the Design screen in VS2008 SP1, so I would image it will be the last thing to be added to a page?

Any ideas how I might fix either?

Thanks once again

Regards

Oct 18, 2011 at 2:37 PM

Now sure how you connected the bind the sql data to your control, but I used a datatable and it works fine.  Not sure about your other problem.

 

	    DataTable _DataTable = null;
            //use to load the multiselech checkboxes during searching
            
            _DataTable.Columns.Add(new DataColumn("id", typeof(System.String)));
            _DataTable.Columns.Add(new DataColumn("name", typeof(System.String)));

	    while (reader.Read()){
	         _DataTable.Rows.Add(new string[] {reader["sqlfield_Id"].ToString(), reader["sqlfield_name"].ToString()});
	    }

	    droDownSelect.DataSource = _DataTable;
            droDownSelect.DataTextField = "name";
            droDownSelect.DataValueField = "id";
            droDownSelect.DataBind();

Oct 25, 2011 at 10:29 PM

Hi t4nguyen

I create the dropdownboxes using an sqldatasource

<div style="padding-top: 20px;">
<asp:DropDownCheckBoxes ID="ProductCheckBoxes" runat="server"
OnSelectedIndexChanged="ProductCheckBoxes_SelectedIndexChanged"
AddJQueryReference="True" UseButtons="True" UseSelectAllNode="False"
        DataSourceID="SqlDataSource1" RepeatDirection="Horizontal"
        DataTextField="Item" DataValueField="ProductId" >
<Style2 SelectBoxWidth="160px" DropDownBoxBoxWidth="250px" DropDownBoxBoxHeight="200px" />
 <Texts SelectBoxCaption="Product selection" />
</asp:DropDownCheckBoxes>

</div>
<div style="padding-top: 20px;">
<h3>Selected items (updated whenever postback from any of the controls occurs)</h3>
<asp:Panel ID="ProductSelectedItemsPanel" runat="server">
</asp:Panel>
</div>

and in the code behind file

Protected Sub ProductCheckBoxes_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        For Each item As ListItem In TryCast(sender, ListControl).Items
            If item.Selected Then
                ProductSelectedItemsPanel.Controls.Add(New LiteralControl With {.Text = item.Text + " : " + item.Value & "<br/>"})
            End If
        Next
    End Sub

and I get the following result when I select the checkboxes

Washer/Dryer : 3
Stove/Oven : 4
Washer/Dryer : 3
Stove/Oven : 4

As you can see I get a double up on the print out.

I have tried databinding the DropDownCheckBoxes with code but get the same result.

The Design screen issue seems to have resolved itself.

Any ideas?

Thanks for your input.

Regards

Oct 26, 2011 at 1:30 PM

Offhand, I can't tell without stepping through the codes.

What does sender object contains before the For Each? Is the data repeated when it came in or during the for loooop?  Did you inspect the html and see what data is actually in the control you created?

Let me know...when I did mine, I grabbed the items directly from javascript by looping through the checked boxes that was created by the control.