PDA

View Full Version : [CLOSED] Problem to show SelectedItem in Combobox v2.0



Oliver
May 27, 2012, 12:19 AM
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:



<%@ 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

Daniil
May 28, 2012, 3:25 PM
Hi,

I think you should set up Mode to Raw for the ListItem.

dbTipoPedido.SelectedItems.Add(new Ext.Net.ListItem
{
Value = ped.nCdTipoPedido.ToString(),
Mode = ParameterMode.Raw
});
as ValueField has Int type.

Oliver
May 28, 2012, 4:56 PM
Hi,

I think you should set up Mode to Raw for the ListItem.

dbTipoPedido.SelectedItems.Add(new Ext.Net.ListItem
{
Value = ped.nCdTipoPedido.ToString(),
Mode = ParameterMode.Raw
});
as ValueField has Int type.

Hi Daniil,

It works!!!

Thanks a lot!

Oliver