May 26, 2012, 11:19 PM
[CLOSED] Problem to show SelectedItem in Combobox v2.0
Hello!
I need to set some value to the SelectedItem of a combobox but my code is not working, please could you help me to find what is wrong and fix it.
Here a part of code to check:
Thanks in advance.
Oliver
I need to set some value to the SelectedItem of a combobox but my code is not working, please could you help me to find what is wrong and fix it.
Here a part of code to check:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="CadPedido.aspx.cs" Inherits="CadPedido"
Title="Pedido de Venda" %>
<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
<link href="/examples.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.dot-label
{
font-weight: bold;
font-size: 20px;
}
.note .x-form-item
{
margin-bottom: 0px;
}
.note .x-form-display-field
{
color: gray;
padding-top: 0px;
padding-left: 105px;
margin-bottom: 5px;
}
.x-mcombo-item-disabled
{
opacity: 1;
filter: alpha(opacity=100);
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<ext:ResourceManager ID="ResourceManager2" runat="server" />
<ext:Panel ID="Panel2" runat="server" Layout="FitLayout" Frame="true">
<Items>
<ext:FormPanel ID="FormPanel2" runat="server" Title="Dados do Pedido" BodyPadding="5"
ButtonAlign="Left" Frame="true" Layout="FitLayout" Height="510">
<Items>
<ext:Container ID="Container1" runat="server" Layout="Column" AutoHeight="true">
<Items>
<ext:Container ID="Container2" runat="server" Layout="AnchorLayout" ColumnWidth=".2">
<Items>
<ext:ComboBox ID="dbTipoPedido" runat="server" Editable="true" Height="20px" FieldLabel="Tipo Pedido"
Width="403" ReadOnly="false" AnchorHorizontal="95%" LabelAlign="Right" QueryMode="Local"
DisplayField="cNmTipoPedido" ValueField="nCdTipoPedido" TriggerAction="Query"
EmptyText="Selecionar..." TypeAhead="true" ForceSelection="true">
<Store>
<ext:Store ID="StoreTipoPedido" runat="server" AutoLoad="true">
<Model>
<ext:Model ID="Model2" IDProperty="nCdTipoPedido" runat="server">
<Fields>
<ext:ModelField Name="nCdTipoPedido" Type="Int" />
<ext:ModelField Name="cNmTipoPedido" Type="String" />
</Fields>
</ext:Model>
</Model>
</ext:Store>
</Store>
</ext:ComboBox>
</Items>
</ext:Container>
</Items>
</ext:Container>
</Items>
</ext:FormPanel>
</Items>
</ext:Panel>
</div>
</form>
</body>
</html>
In the code cs: protected void Page_Load(object sender, EventArgs e)
{
if (!X.IsAjaxRequest)
{
posicionarTipoPedido();
posicionarRegistro(Request["Id"].ToString());
}
}
private void posicionarTipoPedido()
{
var lista = from f in dc.TipoPedidos
orderby f.cNmTipoPedido
select new
{
f.nCdTipoPedido,
f.cNmTipoPedido
};
this.StoreTipoPedido.DataSource = lista;
this.StoreTipoPedido.DataBind();
}
private void posicionarRegistro(string _codigoPedido)
{
ModeloDataContext dc = new ModeloDataContext();
Pedido ped = dc.Pedidos.FirstOrDefault(p1 => p1.nCdPedido == Convert.ToInt32(Request["Id"].ToString()));
if (ped != null)
{
dbTipoPedido.SelectedItems.Add(new Ext.Net.ListItem { Value = ped.nCdTipoPedido.ToString() });
dbTipoPedido.UpdateSelectedItems();
}
return;
}
In Watch Window, the value of selecteditem is correct, but when the form is show, no item is selected.Thanks in advance.
Oliver
Last edited by Daniil; May 28, 2012 at 4:40 PM.
Reason: [CLOSED]