This is a migrated thread and some comments may be shown as answers.

Bind to combobox after populating

2 Answers 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Trevor
Top achievements
Rank 1
Trevor asked on 19 Aug 2010, 06:26 PM
Hi,

I have a combobox within a griditemtemplate. This combobox is being populated in sql by using the following code.

Protected Sub RadGrid1_ItemDataBound(ByVal sender As Object, ByVal e As GridItemEventArgs)
        If e.Item.ItemType = 2 And e.Item.IsInEditMode Then
            Dim editform As GridDataItem = CType(e.Item, GridDataItem)
            Dim comboBox As RadComboBox = editform.FindControl("cmboDomains")
            PopulateComboEmail(comboBox)
        End If
    End Sub

The problem I have now is that I want to bind a value from the grid as the text for this combobox only after the combobox has been populated. As of right now, the combobox comes up empty because I try to bind the text value before there are any values in the combobox.

<telerik:RadTextBox id="txtEmailAddress" runat="server" MaxLength="150" Width="200" Text='<%# Bind("proxyAddresses") %>'/>@<telerik:RadComboBox ID="cmboDomains" runat="server" Width="200" text="'<%# Bind("domain") %>'"></telerik:RadComboBox>


Please let me know how I can achieve this!

Thanks!
Trevor

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 20 Aug 2010, 07:10 AM
Hello,


You could set the SelectedValue from code behind itself after binding the combo. Get the cell value by using ColumnUniqueName and set the combobox value. You need to pass the cell value to PopulateComboMail() method for that.

The following help documentation shows how to access cell value.
Accessing cells and rows


-Shinu.
0
Trevor
Top achievements
Rank 1
answered on 20 Aug 2010, 04:35 PM
Hi, thanks for the response. I do not understand how getting the cell value will help me. What I need is the "domain" value which is coming from the objectDataSource that is bound to the grid. Therefore there are two binds. The first bind is coming from sql which populates my comboBox with domain names.

testdomain.edu
test.com
ect.

As you can see I am doing this already and it works fine. However, I also need to bind the value that is coming from the grid datasource to the combobox selected value. So lets say there is an email joecustomer@testdomain.com.

Well I have bound joecustomer to a textbox just fine. Now, I need to bind the testdomain.com portion to my combobox which I assumed would work fine by putting the text value of the combo box as text='<%# bind("domain") %>'. However it binds to the grid before the combobox populates.

Does this make sense? Could someone give me a code example to help?

Thanks
Tags
Grid
Asked by
Trevor
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Trevor
Top achievements
Rank 1
Share this question
or