方法:

public GridViewRow GetCurrentRow(Object CtrlInCell)
        {
            Control Ctrl = (Control)CtrlInCell;
            int Count = 0;
            while ((Ctrl = Ctrl.Parent) != null && Count < 5)
            {
                if (Ctrl.GetType().Name.IndexOf("Cell") >= 0)
                {
                    return (GridViewRow)Ctrl.Parent;
                }
                Count++;
            }
            return null;
        }

 

HTML代码

 

<CommonCtrl:ExtGridView ID="GV1" runat="server" width="100%"  AutoGenerateColumns="False"  DataKeyNames="ItemType" OnRowDataBound="GV1_RowDataBound" >
                            <Columns>
                                <asp:BoundField DataField="ItemType" HeaderText="型">
                                <itemstyle HorizontalAlign="Left" verticalalign="Top" />
                                </asp:BoundField>
                               <asp:TemplateField HeaderText="">
                                    <itemtemplate>
                                        <CommonCtrl:ExtGridView ></asp:Button>
                                        </ItemTemplate>

                                        <ItemStyle HorizontalAlign="Left"></ItemStyle>
                                        </asp:TemplateField>
                                        <asp:TemplateField HeaderText="类型" Visible="False"><ItemTemplate>
                                              <asp:Label ID="lb_Type" runat="server" Text='<%# Eval("ItemType") %>'></asp:Label>
                                              <asp:Label ID="lb_ID" runat="server" Text='<%# Eval("ID") %>'></asp:Label>        
                                               <asp:Label ID="taoka" runat="server" ></asp:Label>          
                                        </ItemTemplate>
                                        <ItemStyle HorizontalAlign="Left"></ItemStyle>
                                        </asp:TemplateField>
                                        </Columns>
                                        </CommonCtrl:ExtGridView>
                                       
</itemtemplate>
                                <itemstyle HorizontalAlign="Left" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="type"  >
                                    <ItemTemplate>
                                        <asp:Label ID="lb_tktype" runat="server" Text='<%# Eval("tkItemType") %>'></asp:Label>
                                   
</ItemTemplate>
                                    <itemstyle verticalalign="Top" />
                                </asp:TemplateField>
                            </Columns>
                        </CommonCtrl:ExtGridView>

 

 

//GridVIew控件调用的方法

protected void Button1_Click(object sender, EventArgs e)
    {
        GridViewRow row = GetCurrentRow(sender);
        DropDownList ddl = (DropDownList)row.Cells[1].FindControl("ddl_TK");  //

        Label lb_ID = (Label)row.Cells[2].FindControl("lb_ID");               //

        if (ddl == null || lb_ID==null)  return;

        bool result= DBMng.ExeUpdate("T5UITempletDefine/update/Update", CommonFunctions.GetInitHashtable("ID", lb_ID.Text.Trim()), CommonFunctions.GetInitHashtable("MapID", ddl.SelectedValue))>0;
        if (result)
        {
            ClientMsgBox("绑定成功");
            BindGV1();
        }
    }

 

相关文章: