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

Setting comboBox with original value in Edit Mode

6 Answers 168 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Milan Gurung
Top achievements
Rank 1
Milan Gurung asked on 09 Sep 2008, 04:52 PM
Hi,$0$0$0$0Could you please help me out to resolve the problem stated below?$0$0$0$0$0I have a RadGrid bound to dataset and I am using inPlace mode for editing purpose. For one of the column I need to have ComboBox. Now I would like to have the selected value in the ComboBox  set to the original value when it goes in Edit mode.$0$0For instance - if the original value is US then US needs to be selected in the ComboBox when it is in Edit mode.$0$0$0$0$0Any suggestion would be appreciated.$0$0$0$0$0Thanks a lot.$0$0Milan G$0$0$0$0$0$0$0

6 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 10 Sep 2008, 08:06 AM
Hi,

Try  binding the SelectedValue of the combobox in the edit form.

<rad:GridTemplateColumn HeaderText="Country" UniqueName="CountryColumn">
     <EditItemTemplate>
        <asp:DropDownList id="ddList1" Height="200px" runat="server"
         DataTextField="Country"
         DataValueField="Country"
         DataSource='<%# LoadCountryNames()  %>'
         SelectedValue='<%# Bind("Country")%>' />
     </EditItemTemplate>
........................

Thanks,
Princy

0
Milan Gurung
Top achievements
Rank 1
answered on 10 Sep 2008, 08:38 AM
Hi Princy,

FYI, I am using ASP.NET 2.0 and I just couldn't find SelectedValue property neither in rad:combobox nor in asp:dropdownlist.

Thanks.
Milan G
0
Shinu
Top achievements
Rank 2
answered on 10 Sep 2008, 09:20 AM
Hello Milan,

The SelectedValue property of the RadComboBox will not be recognized by Intellisense. Try typing it on the aspx side. It will work as expected.

Shinu.
0
Milan Gurung
Top achievements
Rank 1
answered on 10 Sep 2008, 09:41 AM
Thanks for the tip. Now the trouble is I am getting "Selection out of range" javascript error. clicking on edit button.

Any pointer?

Thanks again.
Milan G
0
Milan Gurung
Top achievements
Rank 1
answered on 10 Sep 2008, 09:44 AM

Here is a snippet of the code..

<telerik:GridTemplateColumn HeaderText="Client" UniqueName="Client">
                    <ItemTemplate>
                        <asp:Label ID="lblClient" runat="server" Text='<%#Eval("Budget_Client")%>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="lstClient" runat="server" DataSourceID="SrcForClient" DataTextField="ClientName" DataValueField="ClientID" SelectedValue='<%#Eval("Budget_Client")%>'>
                        </telerik:RadComboBox>
                        <asp:Label ID="lblOriginalClient" runat="server" Text='<%#Eval("Budget_Client")%>'></asp:Label>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

Somewhere down ..

<asp:ObjectDataSource ID="SrcForClient" runat="server" SelectMethod="GetAllClient" TypeName="ProjectX.ClientManager"></asp:ObjectDataSource>

Could you please let me know what is wrong?

Thanks a lot

Milan G

0
Milan Gurung
Top achievements
Rank 1
answered on 10 Sep 2008, 09:57 AM

Sorry..I made the mistake by in assigning selectedValue. This is done now. Further down, why is the new selection made in the combo box not reflected when clicking update button?

Code Snippet..

<telerik:GridTemplateColumn HeaderText="Client" UniqueName="Client">
                    <ItemTemplate>
                        <asp:Label ID="lblClient" runat="server" Text='<%#Eval("Budget_Client")%>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="lstClient" runat="server" DataSourceID="SrcForClient" DataTextField="ClientName" DataValueField="ClientID" SelectedValue='<%#Eval("Budget_Client")%>'>
                        </telerik:RadComboBox>
                        <asp:Label ID="lblOriginalClient" runat="server" Text='<%#Eval("Budget_Client")%>'></asp:Label>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>

Somewhere down ..

<asp:ObjectDataSource ID="SrcForClient" runat="server" SelectMethod="GetAllClient" TypeName="ProjectXX.ClientManager"></asp:ObjectDataSource>

Corresponding codebehind file..

Protected

Sub gridException_UpdateCommand(ByVal source As System.Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gridException.UpdateCommand

Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)

Dim exceptionTable As DataTable = Me.GridSource

Dim id As String

id =

CType(editedItem("BudgetExceptionID").Controls(0), TextBox).Text

lblErrorMsg.Text = id.ToString() +

"testing"

'Locate the changed row in the DataSource

Dim changedRows() As DataRow = exceptionTable.Select("BudgetExceptionID = " & id)

If (changedRows.Length <> 1) Then

lblErrorMsg.Text =

"Unable to locate the Order for updating."

e.Canceled =

True

Return

End If

'Update new values

Dim newValues As Hashtable = New Hashtable

'The GridTableView will fill the values from all editable columns in the hash

e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem)

changedRows(0).BeginEdit()

Try

For Each entry As DictionaryEntry In newValues

changedRows(0)(

CType(entry.Key, String)) = entry.Value

Next

changedRows(0).EndEdit()

Catch ex As Exception

changedRows(0).CancelEdit()

lblErrorMsg.Text =

"Unable to update Orders. Reason: " & ex.Message

e.Canceled =

True

End Try

End Sub


Tags
Grid
Asked by
Milan Gurung
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Milan Gurung
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or