telerik的RadComboBox丢失了SelectedValue

时间:2016-12-14 14:53:46

标签: c# asp.net telerik

当我尝试在DB中插入时,我有一个Telerik的RadComboBox丢失了selectedValue。它在执行期间始终具有值,但是当我单击保存按钮时,我看到RadComboBox仅丢失了SelectedValue,它不会使文本仅丢失int值。我使用asp.net和c#。

请帮助我提出您的意见和建议。感谢。

<!-- Definition of cbProg in page aspx-->
<tr style="display: table-row;">
  <td style="display: table-cell; vertical-align: inherit">
    <div style="left: 210px; position: absolute; top: 140px;">
        <label for="cbProg">Programa:</label>
        <div style="left: 65px; position: absolute; top: -10px;">
            <telerik:RadTextBox ID="txtProg" runat="server" Width="40px"      Height="25px" Enabled="true" MaxLength="2"
                BorderColor="#C9D9F8" BorderStyle="Solid" Skin="Silk" ToolTip="Código del Programa al que se asigna el gasto."
                BorderWidth="1px" ReadOnly="false">
            </telerik:RadTextBox>
            <div style="left: 45px; position: absolute; top: 0px;">
                <telerik:RadComboBox ID="cbProg" runat="server" RenderMode="Lightweight" EnableLoadOnDemand="true" Filter="StartsWith" 
                    OnSelectedIndexChanged="cbProg_SelectedIndexChanged" AutoPostBack="true"
                    EmptyMessage="-- Select --" HighlightTemplatedItems="true" Skin="Metro" Width="230px" ToolTip="Nombre del programa al que se asigna el gasto.">
                </telerik:RadComboBox>
                <div style="left: 195px; position: absolute; top: 5px;">
                    <asp:RequiredFieldValidator ID="rfvPrograma" runat="server" ControlToValidate="cbProg"
                     ForeColor="Red" Font-Bold="true" SetFocusOnError="True" ValidationGroup="Guardar"></asp:RequiredFieldValidator>
                </div>
                <div style="left: 235px; position: absolute; top: 1px;">
                    <asp:ImageButton ID="btPrograma" runat="server" Text=""  OnClick="btPrograma_Click"
                      ImageUrl="../Imagenes/find1.png" Width="24px" Height="24px" ></asp:ImageButton>
                </div>
            </div>
        </div>
    </div>
  </td>
</tr>

//Method for list all programs of table in cbProg
public void ListarProgramas()
{
    query = @"SELECT IdLinea, IdPrograma, Descripcion
                FROM PRE_Programas";

    cbComun(cbProg, query, "Descripcion", "IdLinea");
}

//Method for fill all comboBox
public void cbComun(RadComboBox cb, string str, string Texto, string Valor, int a=1 )
{
    DataTable dt = dtSelec(str);
    cb.Items.Clear();

    cb.DataTextField = Texto;
    cb.DataValueField = Valor;

    cb.DataSource = dt;
    cb.DataBind();
}

//Assigned Id Number of Program to other textbox filltering with SelectedValue of cbProg
protected void cbProg_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
{
    query = @"SELECT IdLinea, IdPrograma, Descripcion FROM PRE_Programas WHERE IdLinea='" + cbProg.SelectedValue + "' ";

    txtComun(txtProg, query, "IdPrograma");
}

1 个答案:

答案 0 :(得分:0)

尝试在Page_Init事件中绑定RadComboBox。