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

[Solved] SelectedIndexChanged and Multicolumn question

4 Answers 165 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Ed Staffin
Top achievements
Rank 1
Ed Staffin asked on 24 Aug 2009, 11:10 AM
I have a radcombobox that is following the examples on how to create one that has multiple columns.

The first issue I am having is that when I select an item and it does an autopostback, the selected item is not sticking. It just goes back to the first item in the list. What magic dust do I need to sprinkle to make the selected item stick?

Secondly, in the selectedIndexChanged event handler I look at ddl.SelectedItem.value and it shows it as a string that is set to "DataRowView". I have tried all kinds of ways to cast it to a datarow view with no luck. Below is the aspx code.
Do I need to parse the selectedtext property by hand?
Any help would be really appreciated.
Thanks ... Ed
            <telerik:RadComboBox ID="ddlVoucher" runat="server" Skin="Vista" Width="420"   
            HighlightTemplatedItems="true" AutoPostBack="true" CausesValidation="false" > 
                <HeaderTemplate> 
                  <table style="width: 415px; text-align: left">  
                    <tr> 
                       <td style="width: 60px;">Voucher #</td> 
                       <td style="width: 250px;">Vendor/Staff</td> 
                       <td style="width: 80px;">Due Date</td> 
                       <td style="width: 80px;">Invoice #</td> 
                       <td style="display:none">VoucherId</td> 
                    </tr> 
                  </table> 
                </HeaderTemplate> 
                <ItemTemplate> 
                  <table style="width: 415px; text-align: left">  
                    <tr> 
                       <td style="width: 60px;">  
                           <%#DataBinder.Eval(Container.DataItem, "VoucherNumber")%> 
                       </td> 
                       <td style="width: 250px;">  
                           <%#DataBinder.Eval(Container.DataItem, "VendorOrStaff")%> 
                       </td> 
                       <td style="width: 80px;">  
                           <%#DataBinder.Eval(Container.DataItem, "DueDate")%> 
                       </td> 
                       <td style="width: 80px;">  
                           <%#DataBinder.Eval(Container.DataItem, "InvoiceNumber")%> 
                       </td> 
                       <td style="width: 0px;">  
                           <%#DataBinder.Eval(Container.DataItem, "PaymentVoucherId")%> 
                       </td> 
                    </tr> 
                  </table> 
                </ItemTemplate> 
                  
 
            </telerik:RadComboBox> 


    Protected Sub ddlVoucher_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles ddlVoucher.ItemDataBound  
        e.Item.Text = _ 
        (DirectCast(e.Item.DataItem, DataRowView))("VoucherNumber").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("VendorOrStaff").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("DueDate").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("InvoiceNumber").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("PaymentVoucherId").ToString()  
 
        'e.Item.Text = _ 
        '(DirectCast(e.Item.DataItem, DataRowView))("VoucherNumber").ToString() & "; " & _  
        '(DirectCast(e.Item.DataItem, DataRowView))("VendorOrStaff").ToString()  
 
    End Sub  
 

4 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 24 Aug 2009, 02:51 PM
Hi Ed Staffin,

I could not reproduce the first issue.

As for the second question - in order to use the Value property you need to set it first.
In ItemDataBound event you set the Text property, please set the Value property of the item as well and the code should start working.

Please find attached a sample working project.

Kind regards,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ed Staffin
Top achievements
Rank 1
answered on 25 Aug 2009, 02:44 PM
Hi,
I understand about the value now, but I am still having the problem with autopostback.
Below is the simplest example I could come up with. Just run it and selected any item other than the first one and it will post back.
WHen it comes back from the postback the first item is ALWAYS selected.
I must be missing something simple.
Thanks ... Ed

<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MultiColCombo.aspx.vb" Inherits="MultiColCombo" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title></title>  
</head> 
<body> 
    <form id="form1" runat="server">  
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" runat="server">  
        </telerik:RadScriptManager> 
            <telerik:RadComboBox ID="ddlVoucher" runat="server" Skin="Vista" Width="420"   
            HighlightTemplatedItems="true" AutoPostBack="true" CausesValidation="false" > 
                <HeaderTemplate> 
                  <table style="width: 415px; text-align: left">  
                    <tr> 
                       <td style="width: 60px;">Voucher #</td> 
                       <td style="width: 250px;">Vendor/Staff</td> 
                       <td style="width: 80px;">Due Date</td> 
                       <td style="width: 80px;">Invoice #</td> 
                       <td style="display:none">VoucherId</td> 
                    </tr> 
                  </table> 
                </HeaderTemplate> 
                <ItemTemplate> 
                  <table style="width: 415px; text-align: left">  
                    <tr> 
                       <td style="width: 60px;">  
                           <%#DataBinder.Eval(Container.DataItem, "VoucherNumber")%> 
                       </td> 
                       <td style="width: 250px;">  
                           <%#DataBinder.Eval(Container.DataItem, "VendorOrStaff")%> 
                       </td> 
                       <td style="width: 80px;">  
                           <%#DataBinder.Eval(Container.DataItem, "DueDate")%> 
                       </td> 
                       <td style="width: 80px;">  
                           <%#DataBinder.Eval(Container.DataItem, "InvoiceNumber")%> 
                       </td> 
                       <td style="width: 0px;">  
                           <%#DataBinder.Eval(Container.DataItem, "PaymentVoucherId")%> 
                       </td> 
                    </tr> 
                  </table> 
                </ItemTemplate> 
                  
 
            </telerik:RadComboBox> 
          
    </div> 
    </form> 
</body> 
</html> 
 

Imports System.Data  
 
Partial Class MultiColCombo  
    Inherits System.Web.UI.Page  
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load  
        If Not IsPostBack Then  
 
            Dim ds As New DataSet  
            ds.ReadXml(Server.MapPath("TestData.xml"))  
            ddlVoucher.DataSource = ds.Tables(0)  
 
            ddlVoucher.DataBind()  
 
 
        End If  
    End Sub  
    Protected Sub ddlVoucher_ItemDataBound(ByVal sender As Object, ByVal e As Telerik.Web.UI.RadComboBoxItemEventArgs) Handles ddlVoucher.ItemDataBound  
        e.Item.Text = _ 
        (DirectCast(e.Item.DataItem, DataRowView))("VoucherNumber").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("VendorOrStaff").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("DueDate").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("InvoiceNumber").ToString() & "; " & _  
        (DirectCast(e.Item.DataItem, DataRowView))("PaymentVoucherId").ToString()  
        e.Item.Value = (DirectCast(e.Item.DataItem, DataRowView))("PaymentVoucherId").ToString()  
    End Sub  
 
    Protected Sub ddlVoucher_SelectedIndexChanged(ByVal o As Object, ByVal e As Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventArgs) Handles ddlVoucher.SelectedIndexChanged  
 
    End Sub  
End Class  
 

Just save this xml as testdata.xml in the same directory as the other files.
<NewDataSet> 
 <Data> 
  <VoucherNumber>6</VoucherNumber> 
  <VendorOrStaff>Administrator, Administrator</VendorOrStaff> 
  <DueDate>2008-11-01T00:00:00-04:00</DueDate> 
  <InvoiceNumber>1</InvoiceNumber> 
  <PaymentVoucherId>123</PaymentVoucherId> 
 </Data> 
 <Data> 
  <VoucherNumber>8</VoucherNumber> 
  <VendorOrStaff>Norman, Gary</VendorOrStaff> 
  <DueDate>1980-01-01T00:00:00-05:00</DueDate> 
  <InvoiceNumber>1</InvoiceNumber> 
  <PaymentVoucherId>123</PaymentVoucherId> 
 </Data> 
 <Data> 
  <VoucherNumber>10</VoucherNumber> 
  <VendorOrStaff>Hall, Kjersti</VendorOrStaff> 
  <DueDate>2007-08-20T00:00:00-04:00</DueDate> 
  <InvoiceNumber>1</InvoiceNumber> 
  <PaymentVoucherId>123</PaymentVoucherId> 
 </Data> 
</NewDataSet> 
 
0
Accepted
Veselin Vasilev
Telerik team
answered on 26 Aug 2009, 08:56 AM
Hi Ed Staffin,

The problem occurs because the Value of the items are the same ("123"). The value properties must be unique. Here is what you can do:

e.Item.Value = e.Item.Text

I hope this helps.

All the best,
Veselin Vasilev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Ed Staffin
Top achievements
Rank 1
answered on 26 Aug 2009, 10:07 AM
Outstanding catch. Boy do  I feel dumb. That'll teach me to cut and paste to set up test data!
Jeez. Thanks
Tags
ComboBox
Asked by
Ed Staffin
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
Ed Staffin
Top achievements
Rank 1
Share this question
or