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

I can't get GridDropDownColumn correct selectedvalue at InsertCommand()

1 Answer 74 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JACK KUO
Top achievements
Rank 1
JACK KUO asked on 08 Oct 2008, 02:02 PM
When I select a new value on GridDropDownColumn.
Then I click insert to do InsertCommand event.
But I can't get the select value; I get this value which is Page_init default value.
e.g. strGlobal_App = ""; not strGlobal_App = "XXX"

ps. It neither works correctly by GridTextColumnEditor.

Thanks for your help.


Here is my sample code:

    <telerik:RadGrid ID="grd" runat="server"  AllowAutomaticInserts="True"
        AllowAutomaticUpdates="True" AllowAutomaticDeletes="True"
oninsertcommand="grd_InsertCommand">
        <MasterTableView DataKeyNames="GUI" AutoGenerateColumns="False"
            CommandItemDisplay="TopAndBottom" HorizontalAlign="NotSet"
                InsertItemDisplay="Top"
            InsertItemPageIndexAction="ShowItemOnFirstPage" >
            <RowIndicatorColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </RowIndicatorColumn>
            <ExpandCollapseColumn>
                <HeaderStyle Width="20px"></HeaderStyle>
            </ExpandCollapseColumn>
            <Columns>
                <telerik:GridDropDownColumn UniqueName="Global_App" ListTextField="comment" ListValueField="value"
                    DataSourceID="XmlDataSource_Global_App" HeaderText="Global_App" DataField="Global_App"
                    DropDownControlType="RadComboBox" AllowSorting="true">
                </telerik:GridDropDownColumn>
                
            </Columns>
            <CommandItemSettings AddNewRecordText="Add new record" AddNewRecordImageUrl="img/AddRecord.gif"
                                     RefreshText="Refresh" RefreshImageUrl="img/Refresh.gif" />

<EditFormSettings>
<EditColumn UniqueName="EditCommandColumn1"></EditColumn>
</EditFormSettings>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="True" />
        </ClientSettings>
        <FilterMenu EnableTheming="True">
            <CollapseAnimation Type="OutQuint" Duration="200"></CollapseAnimation>
        </FilterMenu>
    </telerik:RadGrid>

        protected void grd_InsertCommand(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            GridEditableItem item = (GridEditableItem)e.Item;  
            string strGlobal_App = (item.EditManager.GetColumnEditor("Global_App") as GridDropDownColumnEditor).SelectedValue;

             ~do insert into sql table~
        }

1 Answer, 1 is accepted

Sort by
0
JACK KUO
Top achievements
Rank 1
answered on 09 Oct 2008, 06:31 AM
I get the point!!
The grid data source can't bind data at Page_load( ).
To init grid  data source setting must be at grd_NeedDataSource( ),
and set event of grd_PreRender( ).

        protected void grd_PreRender(object sender, EventArgs e)
        {
            if (!this.IsPostBack)
            {
                this.grd.MasterTableView.Rebind();
            }
        }


        private DataTable GridSource
        {
            get
            {
                DataTable ret_dt;
                Object obj = this.ViewState["grd"];

                if (obj != null)
                    ret_dt = (DataTable)obj;
                else
                {
                    ret_dt = m_HrData.GlobalApplication;
                    this.ViewState["grd"] = ret_dt;
                }

                return ret_dt;
            }
        }

 

        protected void grd_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
        {
            this.grd.DataSource = this.GridSource;
        }

Tags
Grid
Asked by
JACK KUO
Top achievements
Rank 1
Answers by
JACK KUO
Top achievements
Rank 1
Share this question
or