Listview ItemEditing Findcontrol不起作用 [英] Listview ItemEditing Findcontrol not working

查看:108
本文介绍了Listview ItemEditing Findcontrol不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

.aspx


.aspx


<asp:ListView ID="productListView" runat="server" DataKeyNames="ProductID" ItemPlaceholderID="_placeholder" OnItemDataBound="productListView_ItemDataBound"

 OnItemEditing="productListView_ItemEditing" OnItemCanceling="productListView_ItemCanceling" OnItemUpdating="productListView_ItemUpdating"

 OnItemInserting="productListView_ItemInserting" InsertItemPosition="LastItem" OnItemDeleting="productListView_ItemDeleting">

       <LayoutTemplate>

            <table id="headerTable" runat="server" >
            <tr id="Tr1" runat="server">
            <th id="Th11" runat="server">Image</th>
            <th id="Th3" runat="server">Product Name</th>
            <th id="Th5" runat="server">Category</th>
            <th id="Th1" runat="server">Description</th>
            <th id="Th10" runat="server">Show In ProductList</th>

            </tr>
            <tr id="_placeholder" runat="server"></tr>
            </table>

        </LayoutTemplate>

        <ItemTemplate>
                <tr runat="server" id="_placeholder" >
                    <td>
                    <asp:Image ID="imgProduct" runat="server" />
                    </td>
                    <td>
                    <asp:Label ID="NameLabel" runat="server" Text="<%# Bind('Name') %>"></asp:Label>
                    </td>

                    <td>
                    <asp:Label ID="CategoryNameLabel" runat="server" Text="<%# Bind('ProductCategory.CategoryName') %>"></asp:Label>
                    </td>

                    <td>
                    <asp:Label ID="DescriptionLabel" runat="server" Text="<%# Bind('Description') %>"></asp:Label>
                    </td>

                    <td>
                    <asp:Label ID="ShowInProductListLabel" runat="server" Text="<%# Bind('ShowInProductList') %>"></asp:Label>
                    </td>
                    <td>
                    <asp:Button ID="Button1" runat="server" CommandName="Delete" Text="Delete" />
                    <asp:Button ID="Button2" runat="server" CommandName="Edit" Text="Edit" />
                    </td>
                </tr>
            </ItemTemplate>

            <EditItemTemplate>
                <tr runat="server" id="_placeholder" >
                    <td>
                        <asp:FileUpload ID="imgProduct2" runat="server" Text='<%# DataBinder.Eval(Container.DataItem, "Image") %>' />
                    </td>
                    <td>
                        <asp:TextBox ID="NameTextBox" runat="server" Text="<%# Bind('Name') %>"></asp:TextBox>
                    </td>

                    <td>
                        <asp:DropDownList ID="ProductCategoryDDL" runat="server"></asp:DropDownList>
                    </td>


                    <td>
                        <asp:TextBox ID="DescriptionTextBox" runat="server" Text="<%# Bind('Description') %>"></asp:TextBox>
                    </td>

                    <td>
                        <asp:DropDownList ID="ShowInProductListDDL" runat="server">
                            <asp:ListItem>Yes</asp:ListItem>
                            <asp:ListItem>No</asp:ListItem>
                        </asp:DropDownList>
                    </td>
                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" />
                        <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                    </td>
                </tr>
            </EditItemTemplate>

            <InsertItemTemplate>
                <tr runat="server" id="_placeholder">
                    <td>
                        <asp:TextBox ID="NameLabelTextBox" runat="server" Text="<%# Bind('NameLabel') %>"></asp:TextBox>
                    </td>

                    <td>
                        <asp:TextBox ID="CategoryNameTextBox" runat="server" Text="<%# Bind('ProductCategory.CategoryName') %>"></asp:TextBox>
                    </td>


                    <td>
                        <asp:Button ID="UpdateButton" runat="server" CommandName="Insert" Text="Insert" />
                    </td>
                </tr>
            </InsertItemTemplate>


</asp:ListView>




背后的代码

受保护的无效productListView_ItemEditing(对象发送者,ListViewEditEventArgs e)
{

productListView.EditIndex = e.NewEditIndex;
DropDownList PDDL =(DropDownList)productListView.Items [e.NewEditIndex] .FindControl("ProductCategoryDDL");
productListView.EditIndex = e.NewEditIndex;
DataBind();


}

对于产品列表Listview下拉列表PDDL始终为"null",我无法对代码中的Dropdownlist进行细化,任何建议在代码中有什么问题?
谢谢
Chetan.




Code Behind

protected void productListView_ItemEditing(object sender, ListViewEditEventArgs e)
{

productListView.EditIndex = e.NewEditIndex;
DropDownList PDDL = (DropDownList)productListView.Items[e.NewEditIndex].FindControl("ProductCategoryDDL");
productListView.EditIndex = e.NewEditIndex;
DataBind();


}

I am not able to fine the Dropdownlist in code behind for the Product list Listview dropdownlist PDDL is always "null", any suggestions what is wrong in the code??

Thank you,
Chetan.

推荐答案

我认为您应该更早地绑定数据.尝试这种方式.

I think you should data bind earlier. Try this way.

protected void productListView_ItemEditing(object sender, ListViewEditEventArgs e)
{
productListView.EditIndex = e.NewEditIndex;
DataBind();
DropDownList PDDL = (DropDownList)productListView.Items[e.NewEditIndex].FindControl("ProductCategoryDDL");
productListView.EditIndex = e.NewEditIndex;
}


这篇关于Listview ItemEditing Findcontrol不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆