列表视图与ObjectDataSource控件删除不工作 [英] Listview with objectdatasource Delete not working

查看:186
本文介绍了列表视图与ObjectDataSource控件删除不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的用户和放1列表视图; 1 ObjectDataSource控件绑定与ListView。 现在ObjectDataSource的Deletemethod我已经采取了BusinessObject的作为参数,但在运行时我没有得到我的BusinessObject的属性值...

我也尝试使用的ItemTemplate绑定,而不是EVAL。但没有得到我的DeleteMethod在ObjectDataSource的DeleteCommand会提供在运行时的任何值... 任何人可以帮助了解天气,我mising什么还是什么?

我的列表视图的ItemTemplate

 <的ItemTemplate>
            < ASP:HiddenField ID =hidUserAchievementInfoId=服务器值='<%#绑定(UserAchievementInfoId)%> />
            < ASP:HiddenField ID =hidUserIdField=服务器值='<%#绑定(用户ID)%> />
            &其中; TR>
                < TD类=样式1>
                    < ASP:标签ID =AwardLabel=服务器文本=奖>< / ASP:标签>
                < / TD>
                < TD>
                    < ASP:标签ID =lblAward=服务器文本='<%#绑定(奖励)%>'>< / ASP:标签>
                < / TD>
            < / TR>
            &其中; TR>
                < TD类=样式1>
                    < ASP:标签ID =FieldofAwardLabel=服务器文本=奖现场>< / ASP:标签>
                < / TD>
                < TD>
                    < ASP:标签ID =lblFieldofAward=服务器文本='<%#绑定(FieldofAward)%>'>< / ASP:标签>
                < / TD>
            < / TR>
            &其中; TR>
                < TD类=样式1>
                    < ASP:标签ID =TournamentLabel=服务器文本=锦标赛>< / ASP:标签>
                < / TD>
                < TD>
                    < ASP:标签ID =lblTournament=服务器文本='<%#绑定(赛)%>'>< / ASP:标签>
                < / TD>
            < / TR>
            &其中; TR>
                < TD类=样式1>
                    < ASP:标签ID =AwardYearLabel=服务器文本=年度奖>< / ASP:标签>
                < / TD>
                < TD>
                    < ASP:标签ID =AwardYear=服务器文本='<%#绑定(AwardYear)%>'>< / ASP:标签>
                < / TD>
            < / TR>
            &其中; TR>
                < TD类=样式1>
                    < ASP:标签ID =AwardDescriptionLabel=服务器文本=描述>< / ASP:标签>
                < / TD>
                < TD>
                    < ASP:标签ID =lblAwardDescription=服务器文本='<%#绑定(AwardDescription)%>'>< / ASP:标签>
                < / TD>
            < / TR>
            &其中; TR>
                < TD类=样式1>
                    < ASP:LinkBut​​ton的ID =EditButton=服务器的CommandName =编辑文本=编辑>< / ASP:LinkBut​​ton的>
                < / TD>
                < TD>
                    < ASP:LinkBut​​ton的ID =DeleteButton=服务器的CommandName =删除文本=删除>< / ASP:LinkBut​​ton的>
                < / TD>
            < / TR>
        < / ItemTemplate中>
 

  

删除方法应用于目标数据   源的DeleteCommand会

 公共无效DeleteUserAchievementInfo(UserAchivementInfoBO BOInstance)
    {
        尝试
        {
    Int64的UserAchievementInfoId = BOInstance.UserAchievementInfoId
            objUserBasicInfoServiceClient.DeleteUserAchievementInfo(UserAchievementInfoId);
        }
        赶上(例外前)
        {
            HandleException.LogError(前);
        }
    }
 

解决方案

尝试添加的业务对象键字段(如身份证,钥匙......)到ListView DataKeyNames属性。通过这样做,你至少可以得到在删除事件的核心价值。

i have one Listview in my Usercontrol & 1 objectdatasource binded with the ListView. now in objectdatasource's Deletemethod i have taken businessobject as argument but at runtime i am not getting value in my businessobject's properties...

i also tried to use "Bind" instead of "eval" in ItemTemplate. but not getting any value at runtime in my DeleteMethod provided in objectdatasource's Deletecommand... can anybody help to know weather i am mising anything or what?

my Listview's ItemTemplate

 <ItemTemplate>
            <asp:HiddenField ID="hidUserAchievementInfoId" runat="server" Value='<%# Bind("UserAchievementInfoId") %>' />
            <asp:HiddenField ID="hidUserIdField" runat="server" Value='<%# Bind("UserId") %>' />
            <tr>
                <td class="style1">
                    <asp:Label ID="AwardLabel" runat="server" Text="Award "></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblAward" runat="server" Text='<%# Bind("Awards") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:Label ID="FieldofAwardLabel" runat="server" Text="Field of Award "></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblFieldofAward" runat="server" Text='<%# Bind("FieldofAward") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:Label ID="TournamentLabel" runat="server" Text="Tournament "></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblTournament" runat="server" Text='<%# Bind("Tournament") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:Label ID="AwardYearLabel" runat="server" Text="Award Year "></asp:Label>
                </td>
                <td>
                    <asp:Label ID="AwardYear" runat="server" Text='<%# Bind("AwardYear") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:Label ID="AwardDescriptionLabel" runat="server" Text="Description "></asp:Label>
                </td>
                <td>
                    <asp:Label ID="lblAwardDescription" runat="server" Text='<%# Bind("AwardDescription") %>'></asp:Label>
                </td>
            </tr>
            <tr>
                <td class="style1">
                    <asp:LinkButton ID="EditButton" runat="server" CommandName="Edit" Text="Edit"></asp:LinkButton>
                </td>
                <td>
                    <asp:LinkButton ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete"></asp:LinkButton>
                </td>
            </tr>
        </ItemTemplate>

Delete Method used in objectdata source's Deletecommand

    public void DeleteUserAchievementInfo(UserAchivementInfoBO BOInstance)
    {
        try
        {
    Int64 UserAchievementInfoId=BOInstance.UserAchievementInfoId
            objUserBasicInfoServiceClient.DeleteUserAchievementInfo(UserAchievementInfoId);
        }
        catch (Exception ex)
        {
            HandleException.LogError(ex);
        }
    }

解决方案

Try to add the business object key field(e.g id, key...) to the listview datakeynames property. By doing this, you can at least get the key value in the deleting event.

这篇关于列表视图与ObjectDataSource控件删除不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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