0

lblCategoryNameコントロールとを見つけるにはどうすればよいddlBlogCategoryですか?

これが私のコードです:

protected void grdRetailStore_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            Label lblAccount = (Label)e.Row.FindControl("lblCategoryName");
            string s = lblAccount.Text;
            DropDownList ddlBlogCategory =    (DropDownList)e.Row.FindControl("ddlBlogCategoty");
            DAO.DAO dao_category = new DAO.DAO();
            DataTable dt_blog_cat = dao_category.SelectCategory();
            if (ddlBlogCategory != null)
            {
                //  ddlBlogCategory.Items.Clear();
                ddlBlogCategory.DataSource = dao_category.SelectCategory();
                ddlBlogCategory.DataTextField = "CategoryName";
                ddlBlogCategory.DataValueField = "BlogCategoryID";
                ddlBlogCategory.DataBind();
            }
        }
    }


 <asp:GridView ID="grdRetailStore" runat="server" AutoGenerateColumns="false"   DataKeyNames="PortalId" OnRowEditing="grdRetailStore_RowEditing"
                 OnRowCancelingEdit="grdRetailStore_RowCancelingEdit"      OnRowDataBound="grdRetailStore_RowDataBound">
                <Columns>

                    <asp:TemplateField HeaderText="ID">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:Label ID="lblId" runat="server" Text='<%# Bind("PortalId") %>'></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblId" runat="server" Text='<%# Bind("PortalId") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="AdvertiserName">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:TextBox ID="txtAdvName" runat="server" Text='<%# Bind("AdvertiserName") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblAdvName" runat="server" Text='<%# Bind("AdvertiserName") %>'></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="PromoCategory">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                           <%-- <asp:DropDownList ID="" runat="server" DataTextField="Account_Name" DataValueField="Account_Id"
                                AppendDataBoundItems="true">
                                <%-- <asp:ListItem Selected="True" Text="---Select---" Value="0"></asp:ListItem></asp:DropDownList> --%>
                          <asp:TextBox ID="txtPromoCat" runat="server" Text='<%# Bind("PromoCatId") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblPromoCat" runat="server" Text='<%# Bind("PromoCatId") %>'></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="Start Date">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:TextBox ID="txtPromostartdate" runat="server" Text='<%# Bind("PromoStartDate") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblPromostartdate" runat="server" Text='<%# Bind("PromoStartDate") %>'></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>

                     <asp:TemplateField HeaderText="End Date">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:TextBox ID="txtPromoenddate" runat="server" Text='<%# Bind("PromoEndDate") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblPromoenddate" runat="server" Text='<%# Bind("PromoEndDate") %>'></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>



                    <asp:TemplateField HeaderText="Html Code">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:TextBox ID="txtHtml" runat="server" Text='<%# Bind("HtmlCode") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblHtml" runat="server" Text=""></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="CategoryName">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                           <asp:DropDownList ID="ddlBlogCategoty" runat="server" DataTextField="CategoryName" DataValueField="BlogCategoryID"
                                AppendDataBoundItems="true">
                                 <asp:ListItem Selected="True" Text="---Select---" Value="0"></asp:ListItem></asp:DropDownList>
                           </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="lblCategoryName" runat="server" Text='<%# Bind("CategoryName") %>'></asp:Label>
                        </ItemTemplate>

                    </asp:TemplateField>

                    <asp:TemplateField HeaderText="Edit" ShowHeader="False">
                        <HeaderStyle Width="100px" Wrap="False" />
                        <EditItemTemplate>
                            <asp:LinkButton ID="lbkUpdate" runat="server" CausesValidation="True" CommandName="Update"
                                Text="Update" OnClientClick="return ValidateUpdate();"></asp:LinkButton>
                            <asp:LinkButton ID="lnkCancel" runat="server" CausesValidation="False" CommandName="Cancel"
                                Text="Cancel"></asp:LinkButton>
                        </EditItemTemplate>

                        <ItemTemplate>
                            <asp:LinkButton ID="lnkEdit" runat="server" CausesValidation="False" CommandName="Edit"
                                Text="Edit"></asp:LinkButton>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                </asp:GridView>
4

1 に答える 1

0

コードビハインドを変更し、RowState のチェックを含めます。

protected void grdRetailStore_RowDataBound(object sender, GridViewRowEventArgs e)
{
  if (e.Row.RowType == DataControlRowType.DataRow)
  {
      if (e.Row.RowState == DataControlRowState.Normal)
      {
          Label lblAccount = (Label)e.Row.FindControl("lblCategoryName");
          string s = lblAccount.Text;
      }
      if (e.Row.RowState == DataControlRowState.Edit)
      {
          DropDownList ddlBlogCategory = (DropDownList)e.Row.FindControl("ddlBlogCategoty");
          if (ddlBlogCategory != null)
          {
              //  ddlBlogCategory.Items.Clear();
              ddlBlogCategory.DataSource = dao_category.SelectCategory();
              ddlBlogCategory.DataTextField = "CategoryName";
              ddlBlogCategory.DataValueField = "BlogCategoryID";
              ddlBlogCategory.DataBind();
          }
      }
      DAO.DAO dao_category = new DAO.DAO();
      DataTable dt_blog_cat = dao_category.SelectCategory();
  }
}
于 2012-05-17T11:50:01.860 に答える