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

EnableViewstate="false" of combobox

1 Answer 200 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Lenin
Top achievements
Rank 1
Lenin asked on 12 Feb 2009, 10:06 AM
Hi all,
I want to disable  viewstate property of  combo box. if i did, i cannot fill the combobox inside the isnotpostback of page load.
if i fill out of the ispostback, i cannot preserve the selected data of the combo box. 
how can i solve this  problem.? pls help me.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Feb 2009, 07:50 AM
Hi Lenin,
One suggestion is by using a hidden field to capture the selected index value of RadComboBox and set the RadComboBox selected item based on the hidden field value.

CS:
protected void Page_Load(object sender, EventArgs e) 
    { 
            RadComboBoxItem item = new RadComboBoxItem("India","1");            
            RadComboBoxItem item1 = new RadComboBoxItem("usa""2"); 
            RadComboBoxItem item2 = new RadComboBoxItem("Japan""3"); 
            Title.Items.Add(item); 
            Title.Items.Add(item1); 
            Title.Items.Add(item2); 
            if (hdnIndex.Value != String.Empty) 
                  Title.SelectedIndex = Convert.ToInt16(hdnIndex.Value); 
    }  
 

JavaScript:
<script type="text/javascript"
function Select(sender, eventArgs) 
    var item = eventArgs.get_item();    
    var index = item.get_index(); 
    document.getElementById("<%= hdnIndex.ClientID %>").value = index;    
</script>  

ASPX:
<input type="hidden" runat="server" id="hdnIndex" />  

Thanks,
Shinu.


Tags
ComboBox
Asked by
Lenin
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or