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

Get control into GridTemplateColumn when call EditCommand method !?

2 Answers 77 Views
Grid
This is a migrated thread and some comments may be shown as answers.
hongnguyenx
Top achievements
Rank 1
hongnguyenx asked on 15 Oct 2009, 05:58 PM
Hi all,
I have a RADGRID:

<telerik:RadGrid ID="grdHSKT" runat="server"
                        onneeddatasource="grdHSKT_NeedDataSource" Skin="Office2007"
                        AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False"
                        oneditcommand="grdHSKT_EditCommand">
                        <MasterTableView CommandItemDisplay="TopAndBottom" TableLayout="Auto" >
                        <PagerStyle Mode="NextPrevAndNumeric"  />
                            <Columns>
                                <telerik:GridButtonColumn UniqueName="EditColumn" ButtonType="ImageButton" CommandName="Edit" />
                                <telerik:GridBoundColumn DataField="TenHSKemTheo" HeaderText="Tên hồ sơ kèm theo" UniqueName="tenHSKT" DataType="System.String">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="SoBanChinh" HeaderText="Bản chính" UniqueName="banChinh" DataType="System.Int32">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="SoBanSao" HeaderText="Bản sao" UniqueName="banSao" DataType="System.Int32">
                                </telerik:GridBoundColumn>
                                <telerik:GridBoundColumn DataField="GhiChu" HeaderText="Ghi chú" UniqueName="ghiChu" DataType="System.String">
                                </telerik:GridBoundColumn>
                                <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Chọn">
                                <ItemTemplate>
                                    <asp:Panel ID="Panel1" runat="server">
                                        <asp:CheckBox ID="cbActive" Checked="true" runat="server" AutoPostBack="true" OnCheckedChanged="CheckedChanged" />
                                    </asp:Panel>
                                    </ItemTemplate>
                                </telerik:GridTemplateColumn>
                            </Columns>
                            <EditFormSettings ColumnNumber="1" CaptionFormatString="Thay đổi hồ sơ kèm theo:">
                                <FormTemplate>
                                   <table cellspacing="5px" cellpadding="2px">
                                    <tr>
                                        <td>Tên hồ sơ kèm theo: </td>
                                        <td>
                                            <asp:TextBox ID="txtHoSoKemTheo" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "TenHSKemTheo") %>' ></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Số bản chính: </td>
                                        <td>
                                            <asp:TextBox ID="txtSoBanChinh" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SoBanChinh") %>' > </asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Số bản sao: </td>
                                        <td>
                                            <asp:TextBox ID="txtSoBanSao" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "SoBanSao") %>'></asp:TextBox>
                                        </td>
                                    </tr>
                                    <tr>
                                        <td>Ghi chú: </td>
                                        <td>
                                            <asp:TextBox ID="txtMoTa" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "GhiChu") %>'></asp:TextBox>
                                        </td>
                                    </tr>
                                   </table>
                                </FormTemplate>
                            </EditFormSettings>
                        </MasterTableView>
                        <ClientSettings AllowColumnsReorder="True">
                            <Selecting AllowRowSelect="True" />
                        </ClientSettings>
                    </telerik:RadGrid>

And now I want to get checkbox have ID: cbActive into GridTemplateColumn when I call grdHSKT_EditCommand method to set enable property on it !!! But I don' know how to get it !!!
Plz help me !!! Thnks so much for any help.

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 16 Oct 2009, 04:27 AM
Hello,

Try the following code snippet in order to access the checkbox in GridTemplateColumn.

CS:
 
protected void RadGrid1_EditCommand(object source, GridCommandEventArgs e) 
    GridDataItem editItem = (GridDataItem)e.Item; 
    CheckBox chk = (CheckBox)editItem.FindControl("cbActive"); 

-Shinu.
0
hongnguyenx
Top achievements
Rank 1
answered on 16 Oct 2009, 04:26 PM
Hi shinu,
Thnks so much for yours help, but right nwo, I want get it into NeedDatasource method, can do it !?

hongnguyenx
Tags
Grid
Asked by
hongnguyenx
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
hongnguyenx
Top achievements
Rank 1
Share this question
or