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

GridDropDownColumn selected value

3 Answers 299 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Rizwan Ansari
Top achievements
Rank 1
Rizwan Ansari asked on 28 Nov 2010, 06:47 PM

Hello Sir,

 

I have radgird which is bound with sqldatasource..the griddropdown is bound with sqldatasource..
i want when i select the item of dropdown i want to enable or disable checkbox..which is also a bound column in grid.

how can i do this..please help me to solve this issue.

thanks

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Nov 2010, 07:13 AM
Hello Rizwan,

I guess you want to enable/disable the CheckBox based on the selected value of DropDownlist in edit mode. If so the following sample code will be helpful.

ASPX:
<telerik:GridDropDownColumn DataField="FirstName" DataSourceID="SqlDataSource1" ListTextField="FirstName"
    ListValueField="FirstName" UniqueName="GridDropDownColumn" DropDownControlType="DropDownList">
</telerik:GridDropDownColumn>
<telerik:GridCheckBoxColumn DataField="isapproved" UniqueName="GridCheckBoxColumn">
</telerik:GridCheckBoxColumn>

C#:
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
    {
        if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
        {
            GridEditFormItem editItem = (GridEditFormItem)e.Item;
            DropDownList list = (DropDownList)editItem["GridDropDownColumn"].Controls[0];
            list.AutoPostBack = true;
            list.SelectedIndexChanged += new EventHandler(list_SelectedIndexChanged); // attaching SelectedIndexChanged event to GridDropDowmColumn
        }
    }
 
    void list_SelectedIndexChanged(object sender, EventArgs e)
    {
        DropDownList list = (DropDownList)sender;
        GridEditFormItem editItem = (GridEditFormItem)list.NamingContainer;
        CheckBox chkbox = (CheckBox)editItem["GridCheckBoxColumn"].Controls[0]; // accessing CheckBox in GridCheckBoxColumn
        chkbox.Enabled = false;// disabling CheckBox
    }

Thanks,
Princy.
0
Rizwan Ansari
Top achievements
Rank 1
answered on 29 Nov 2010, 07:24 AM
Hi Princy.
Thanks for reply..actually my problem is when the griddropdown selected value is true then i want to enable checkbox.i want two value field in dropdown down column so that i can check if the selected item of griddropdown has value true or false.sqldatasource has some fileds i want the value should be ExpID and NeedApproval .if NeedApproval has value true then the checkbox should be visible.please see the code below. thanks again.
<telerik:RadGrid ID="RadGrid1" runat="server" AllowAutomaticInserts="True" AutoGenerateColumns="False"
    DataSourceID="SqlDataSource5" GridLines="None" Skin="WebBlue" OnItemInserted="RadGrid1_ItemInserted"
    AllowPaging="True" OnDataBound="RadGrid1_DataBound" OnItemDataBound="RadGrid1_ItemDataBound"
    AllowAutomaticDeletes="True" AllowAutomaticUpdates="True" OnItemDeleted="RadGrid1_ItemDeleted"
    OnItemUpdated="RadGrid1_ItemUpdated" >
    <MasterTableView DataSourceID="SqlDataSource5" Width="100%" CommandItemDisplay="Top"
        HorizontalAlign="NotSet" AutoGenerateColumns="false" AllowAutomaticInserts="True"
        ShowGroupFooter="true" AllowPaging="True" DataKeyNames="id" ShowFooter="True" >
        <RowIndicatorColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn>
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <Columns>
            <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn">
                <ItemStyle CssClass="MyImageButton" />
            </telerik:GridEditCommandColumn>
            <telerik:GridDropDownColumn DataField="WH_CODE" HeaderText="WH_CODE" DataSourceID="SqlDataSource3"
                ListTextField="WH_CODE" ListValueField="WH_CODE" ColumnEditorID="GridDropDownColumnEditor1"
                SortExpression="WH_CODE" UniqueName="WH_CODE" ReadOnly="true" Display="True"
                Visible="False">
            </telerik:GridDropDownColumn>
            <telerik:GridDropDownColumn DataField="ExpID" DataType="System.Int32" DataSourceID="SqlDataSource2"
                HeaderText="ExpDesc" ListTextField="ExpDesc" ListValueField="ExpID" ColumnEditorID="GridDropDownColumnEditor1"
                SortExpression="ExpID" UniqueName="ExpID" >
            </telerik:GridDropDownColumn>
            <telerik:GridBoundColumn DataField="InvNo" HeaderText="InvNo" SortExpression="InvNo"
                UniqueName="InvNo">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Amount" DataType="System.Decimal" Aggregate="Sum"
                FooterText="Total Amount:" HeaderText="Amount" SortExpression="Amount" UniqueName="Amount">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="Remark" HeaderText="Remark" SortExpression="Remark"
                UniqueName="Remark">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="id" HeaderText="id" SortExpression="id" UniqueName="id"
                ReadOnly="true" Display="false" Visible="false">
            </telerik:GridBoundColumn>
            <telerik:GridCheckBoxColumn DataField ="approved" HeaderText ="Approved" DataType ="System.Boolean" SortExpression ="approved" UniqueName ="approved">
            </telerik:GridCheckBoxColumn>
                                   <telerik:GridButtonColumn ConfirmText="Delete this record?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete"
                UniqueName="DeleteColumn">
                <ItemStyle HorizontalAlign="Center" CssClass="MyImageButton" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings ColumnNumber="7" CaptionDataField="id" CaptionFormatString="Edit Expence"
            InsertCaption="New Imprest">
            <FormTableItemStyle Wrap="False"></FormTableItemStyle>
            <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
            <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" BackColor="White"
                Width="100%" />
            <FormTableStyle CellSpacing="0" CellPadding="2" Height="110px" BackColor="White" />
            <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
            <EditColumn ButtonType="ImageButton" InsertText="Insert Imprest" UpdateText="Update record"
                UniqueName="EditCommandColumn1" CancelText="Cancel edit">
            </EditColumn>
            <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
        </EditFormSettings>
            </MasterTableView>
    <ClientSettings AllowDragToGroup="true" />
    <GroupingSettings ShowUnGroupButton="true" />
</telerik:RadGrid>

<

 

asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IMPATCHIConnectionString %>"

 

 

SelectCommand="SELECT [ExpID], [ExpEnglishName], [ExpArabicName], [ExpDesc], [NeedApproval], [ApprovalDept] FROM [_Imprest_Master] WHERE (GroupID=1000)">

 

</

 

asp:SqlDataSource>

 


0
Princy
Top achievements
Rank 2
answered on 30 Nov 2010, 11:42 AM
Hello Rizwan,

Make the following modification in your code to achieve this functionality.

C#:
protected void RadGrid2_ItemCreated1(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditFormItem && e.Item.IsInEditMode)
       {
           GridEditFormItem editItem = (GridEditFormItem)e.Item;
           RadComboBox list = (RadComboBox)editItem["ExpID"].Controls[0];
           list.SelectedIndexChanged+=new RadComboBoxSelectedIndexChangedEventHandler(list_SelectedIndexChanged);
           list.AutoPostBack = true;
       }
   }
 
 void list_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
   {
       RadComboBox list = (RadComboBox)sender;
       GridEditFormItem editItem = (GridEditFormItem)list.NamingContainer;
       CheckBox chkbox = (CheckBox)editItem["approved"].Controls[0];
       if (list.SelectedValue == "NeedApproval")
           chkbox.Visible = false;
       else
           chkbox.Visible = true;
   }

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