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

[Solved] DropDown in RadGRID initialing wrong

3 Answers 88 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ricardo
Top achievements
Rank 1
Ricardo asked on 11 Apr 2013, 05:57 PM
Hello Guys, 

I have a datagrid with a column as Dropdown, the update/insert/delete is inline. When I click on EDIT, I want that dropdown load all data from database but the correct register selected. I used the command "combo1.DataValueField = "TM_CP_TIPO_MODULO", but don't working, 

Someone know where are the problem?

===================================================================================

Source code:
===================================================================================
 protected void rdgRegistros_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridEditableItem && e.Item.IsInEditMode)
            {
                
                FitUtil.EncryptedQueryString args = new FitUtil.EncryptedQueryString(Request.QueryString["args"]);
                GestaoClientesDAL.ModulosDAL objModulosDAL = new GestaoClientesDAL.ModulosDAL();
                int idProduto = Convert.ToInt32(args["IdProduto"]);
                DataSet dtsModulos = objModulosDAL.RecuperaModulo(Conexao, idProduto);

                //Popular DropDown em modo edição  
                GridEditableItem editableItem = e.Item as GridEditableItem;
                TextBox txtNome = (editableItem["MO_NOME"].Controls[0] as TextBox);
                TextBox txtCodigo = (editableItem["MO_COD_MODULO"].Controls[0] as TextBox);
                CheckBox chbAtivo = (editableItem["MO_ATIVO"].Controls[0] as CheckBox);

                //Popular DropDown em modo edição                  
                GestaoClientesDAL.TipoModuloDAL objTipoModuloDAL = new GestaoClientesDAL.TipoModuloDAL();
                DataSet dtsTipoModulo = objTipoModuloDAL.ListaTiposModulos(Conexao, idProduto);
                RadComboBox combo1 = (RadComboBox)editableItem["dplTipo"].Controls[0];               

                combo1.DataSource = dtsTipoModulo;
                combo1.DataTextField = "TM_NOME";
                combo1.DataValueField = "TM_CP_TIPO_MODULO";
                combo1.DataBind();

                //Melhorando a largura do componente
                txtNome.Width = 300;
                txtCodigo.Width = 30;
                combo1.Width = 130;
            }
        }
===================================================================================
ASPX
===================================================================================

<telerik:RadGrid ID="rdgRegistros" runat="server" Visible="False" 
                        CssClass="gridPadrao" AllowPaging="True"
                        Width="895px" AutoGenerateColumns="False"  CellSpacing="0" GridLines="None"
                        AllowSorting="True" OnNeedDataSource="rdgRegistros_NeedDataSource" 
                        OnDeleteCommand="rdgRegistros_DeleteCommand" 
                        onupdatecommand="rdgRegistros_UpdateCommand" Culture="pt-BR" 
                        AllowMultiRowEdit="True" onitemdatabound="rdgRegistros_ItemDataBound" 
                        PageSize="5" oninsertcommand="rdgRegistros_InsertCommand">
                        <ClientSettings EnableRowHoverStyle="True">
                        </ClientSettings>                                               

                        <MasterTableView CommandItemDisplay="Top" AutoGenerateColumns="false"
                        DataKeyNames="MO_CP_MODULO" InsertItemPageIndexAction="ShowItemOnCurrentPage">

                            <CommandItemSettings ExportToPdfText="Export to PDF"></CommandItemSettings>
                            <RowIndicatorColumn Visible="True" FilterControlAltText="Filter RowIndicator column">
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </RowIndicatorColumn>
                            <ExpandCollapseColumn Visible="True" FilterControlAltText="Filter ExpandColumn column">
                                <HeaderStyle Width="20px"></HeaderStyle>
                            </ExpandCollapseColumn>

               <EditFormSettings>
                    <EditColumn FilterControlAltText="Filter EditCommandColumn column" >
                    </EditColumn>
                </EditFormSettings>
                            
<Columns>
...
 <telerik:GridDropDownColumn HeaderText="Tipo do Módulo" UniqueName="dplTipo"  DropDownControlType="RadComboBox"
                                    DataType="System.Int32" DataField="TM_NOME" Visible="false">
                                </telerik:GridDropDownColumn>
</Columns>

( I posted only the part referent with my problem )
===================================================================================
Query(SQL)
===================================================================================

public DataSet RecuperaModulo(string conexao, int IdModulo)
        {
            try
            {
                SqlConnection conn = new SqlConnection(conexao);
                SqlDataAdapter da = new SqlDataAdapter();
                SqlCommand cmd = new SqlCommand();
                cmd.Connection = conn;
                cmd.CommandType = CommandType.Text;
                cmd.CommandText = "SELECT * FROM MODULO "
                    + " WHERE MO_CP_MODULO = " + IdModulo.ToString() + " "
                    + " ORDER BY MO_NOME";
                DataSet ds = new DataSet();
                da.SelectCommand = cmd;
                conn.Open();
                da.Fill(ds);
                conn.Close();
                return ds;
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                return null;
            }
        }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 12 Apr 2013, 04:04 AM
Hi,

I suppose you want to make the items selected in dropdowncolumn.
c#:
for (int i = 0; i < combo1.Items.Count; i++)
{
     combo1.Items[i].Selected = true;
}

Thanks,
Shinu
0
Ricardo
Top achievements
Rank 1
answered on 12 Apr 2013, 04:33 PM
Thanks Shinu, But still dont working, :/

Thanks Shinu, But still don't is working, :/

How I can do a append in this component?

table CITY
cityname varchar(50)    / FK STATES
RIO DE JANEIRO        /          RJ      

table STATES
SP
RJ
BA
TO

When I click to edit RIO DE JANEIRO, I want to bring cityname, FK States selected and ALL register from table STATES (sp,rj,ba,to)
0
Princy
Top achievements
Rank 2
answered on 22 Apr 2013, 10:27 AM
Hi,

I guess you want to set the a Datafield selected in the RadComboBox in edit mode. Please take a look into the following code snippet.

C#:
protected void rdgRegistros_ItemDataBound(object sender, GridItemEventArgs e)
{
     if (e.Item is GridEditableItem && e.Item.IsInEditMode)
     {
 
          //your code
      combo1.SelectedValue=(string)DataBinder.Eval(e.Item.DataItem, "Your DataField").ToString();
     }
}

Please elaborate the scenario if it doesn't help.

Thanks,
Princy.
Tags
Grid
Asked by
Ricardo
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ricardo
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or