日期:2014-05-18  浏览次数:20487 次

GridView的RowDataBound问题
GridView的RowDataBound问题

HTML code
前台
 <asp:GridView ID="gvwPurview" runat="server"
AutoGenerateColumns="False"
OnRowDataBound="gvwPurview_RowDataBound"
            OnRowDeleting="gvwPurview_RowDeleting"
OnRowEditing="gvwPurview_RowEditing" DataKeyNames="iPvId"
            OnRowCancelingEdit="gvwPurview_RowCancelingEdit" 
OnRowUpdating="gvwPurview_RowUpdating">
            <Columns>
 <asp:TemplateField HeaderText="上级权限">
                    <ItemTemplate>
                        <%# DataBinder.Eval(Container.DataItem, 

"cPrtName").ToString().Trim() %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <cc1:ParentPurviewDropDownList 

ID="dropEditParentPurview" runat="server">
                        </cc1:ParentPurviewDropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>
<asp:TemplateField HeaderText="类型">
                    <ItemTemplate>
                        <%# DataBinder.Eval(Container.DataItem, 

"cPvType").ToString().Trim() %>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <cc1:PurviewTypeDropDownList 

ID="dropEditPurviewType" runat="server">
                        </cc1:PurviewTypeDropDownList>
                    </EditItemTemplate>
                </asp:TemplateField>

<asp:CommandField UpdateText="更新" HeaderText="编辑" 

CancelText="取消"
                    EditText="编辑" ShowEditButton="True" />
                <asp:CommandField HeaderText="删除" 
                    DeleteText="&lt;div id=&quot;de&quot; 

onclick=&quot;JavaScript:return confirm('确定删除吗?')

&quot;&gt;删除&lt;/div&gt; "  
                    ShowDeleteButton="True" />
            </Columns>
        </asp:GridView>

C# code
后台

/// <summary>
        ///  绑定行时触发
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void gvwPurview_RowDataBound(object sender, 

GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                if (e.Row.RowState == DataControlRowState.Edit)
                {
                   
                    //权限类型
                    PurviewTypeDropDownList dropEditPurviewType 

= (PurviewTypeDropDownList)e.Row.FindControl

("dropEditPurviewType");
                    dropEditPurviewType.DataBind();
                    dropEditPurviewType.SelectedValue = 

DataBinder.Eval(e.Row.DataItem, "iPvType").ToString();

                    //上级权限
                    ParentPurviewDropDownList 

dropEditParentPurview = (ParentPurviewDropDownList)

e.Row.FindControl("dropEditParentPurview");
                    dropEditParentPurview.PurviewID = 

this.txtPrtId.Text;
                    dropEditParentPurview.FDAID = 

this.FDAID.ToString();
                    dropEditParentPurview.DataBind();
                    dropEditParentPurview.SelectedValue = 

DataBinder.Eval(e.Row.DataItem, "iPrtId").ToString();
                }
            }
        }

问题:
当点编辑时,一行可以显示绑定DropDownList控件,另一行不行,不绑定

DropDownList控件。
即一行的e.Row.RowState是DataControlRowState.Edit
而另一行确是DataControlRowS