列表视图和实体框架3.5让我发疯 [英] ListView & entity Framework 3.5 driving me crazy

查看:78
本文介绍了列表视图和实体框架3.5让我发疯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我遇到了问题,我不明白为什么会发生
我有listview,可以使用它与实体框架3.5一起插入,更新和删除
每次我尝试更新或插入以下错误显示

hello, i face problem and i cant understand it why it happen
i have listview which i use it to insert, update and delete with entity framework 3.5
every time i try to update or insert the following error showup

ObjectDataSource 'ODSLanguageLabels' could not find a non-generic method 'UpdateLangLBLs' that has parameters: LangID, LangGrpID, ResourceName, ResourceValue, Language.LangID, Languages_Groups.LangGrpID, ResourceID.


这是我的带有方法的类的代码


and here is my code for the class which has the methods

public bool UpdateLangLBLs(int ResourceID,int LangID, int LangGrpID, string ResourceName, string ResourceValue )
        {
            bool result = false;
            if (ResourceID > 0 && LangID > 0 && LangGrpID > 0 && !string.IsNullOrEmpty(ResourceName) && !string.IsNullOrEmpty(ResourceValue) )
            {
                Languages_Labels updatedLangLab = null;
                using (decorEntities ctx = new decorEntities())
                {
                    updatedLangLab = ctx.Languages_Labels.Where(s => s.ResourceID == ResourceID).FirstOrDefault();
                    if (updatedLangLab != null)
                    {
                        Language selectedLang = ctx.Languages.Where(s => s.LangID == LangID).FirstOrDefault();
                        Languages_Groups selectedLangGrp = ctx.Languages_Groups.Where(s => s.LangGrpID == LangGrpID).FirstOrDefault();
                        updatedLangLab.Language.LangID = selectedLang.LangID;
                        updatedLangLab.Languages_Groups.LangGrpID = selectedLangGrp.LangGrpID;
                        updatedLangLab.ResourceName = ResourceName;
                        updatedLangLab.ResourceValue = ResourceValue;
                        
                        if (ctx.SaveChanges() > 0)
                        {
                            result = true;

                        }
                    }
                }
            }
            return result;
        }

public bool InsertLangLBLs(int langID, int langGrpID, string ResourceName, string ResourceValue)
        {
            bool result = false;
            if (langID > 0 && langGrpID > 0 && !string.IsNullOrEmpty(ResourceName) && !string.IsNullOrEmpty(ResourceValue))
            {
                using (decorEntities ctx = new decorEntities())
                {
                    Language seletctedLanguage = ctx.Languages.Where(s => s.LangID == langID).FirstOrDefault();
                    Languages_Groups selectedLangGrp = ctx.Languages_Groups.Where(g => g.LangGrpID == langGrpID).FirstOrDefault();
                    Languages_Labels newLangLabels = new Languages_Labels();
                    newLangLabels.ResourceName = ResourceName;
                    newLangLabels.ResourceValue = ResourceValue;
                    newLangLabels.Language = seletctedLanguage;
                    newLangLabels.Languages_Groups = selectedLangGrp;

                    ctx.AddToLanguages_Labels(newLangLabels);
                    if (ctx.SaveChanges() > 0)
                    {
                        result = true;
                    }
                }
            }
            return result;
        }


这是我的列表视图


and this is my listview

<asp:ListView ID="LVLangLabels" runat="server" EnableModelValidation="True" InsertItemPosition="LastItem"

                        DataSourceID="ODSLanguageLabels"  

                        DataKeyNames="ResourceID" 

                         

                        onitemcommand="LVLangLabels_ItemCommand">
                        <AlternatingItemTemplate>
                            <tr style="background-color: #FFF8DC;">
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                   <%-- <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Eval("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Eval("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Eval("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="LanguageLabel" runat="server" Text='<%# Eval("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Eval("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </AlternatingItemTemplate>
                        <EditItemTemplate>
                            <tr style="background-color: #008A8C; color: #FFFFFF;">
                                <td>
                                    <asp:Button ID="UpdateButton" runat="server" CommandName="Update" Text="Update" onclick="UpdateButton_Click"/>
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Cancel" />
                                </td>
                                <td>
                                    <%--<asp:TextBox ID="ResourceIDTextBox" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceNameTextBox" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceValueTextBox" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="LanguageTextBox" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="Languages_GroupsTextBox" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </EditItemTemplate>
                        <EmptyDataTemplate>
                            <table  runat="server" style="background-color: #FFFFFF; border-collapse: collapse;
                                border-color: #999999; border-style: none; border-width: 1px;">
                                <tr>
                                    <td>
                                        No data was returned.
                                    </td>
                                </tr>
                            </table>
                        </EmptyDataTemplate>
                        <InsertItemTemplate>
                            <tr style="">
                                <td>
                                    <asp:Button ID="InsertButton" runat="server" CommandName="Insert" Text="Insert" />
                                    <asp:Button ID="CancelButton" runat="server" CommandName="Cancel" Text="Clear" />
                                </td>
                                <td>
                                    <%--<asp:TextBox ID="ResourceIDTextBox" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceNameTextBox" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="ResourceValueTextBox" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="LanguageTextBox" runat="server" Text='<%# Bind("LangID") %>' />
                                </td>
                                <td>
                                    <asp:TextBox ID="Languages_GroupsTextBox" runat="server" Text='<%# Bind("LangGrpID") %>' />
                                </td>
                            </tr>
                        </InsertItemTemplate>
                        <ItemTemplate>
                            <tr style="background-color: #DCDCDC; color: #000000;">
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                   <%-- <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Bind("ResourceID") %>' />--%>
                                </td>
                                <td>
                                    <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Bind("ResourceName") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                </td>
                                <td>
                                    <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                </td>
                            </tr>
                        </ItemTemplate>
                        <LayoutTemplate>
                            <table  runat="server">
                                <tr  runat="server">
                                    <td  runat="server">
                                        <table id="itemPlaceholderContainer"  runat="server" border="1" style="background-color: #FFFFFF;
                                            border-collapse: collapse; border-color: #999999; border-style: none; border-width: 1px;
                                            font-family: Verdana, Arial, Helvetica, sans-serif;">
                                            <tr  runat="server" style="background-color: #DCDCDC; color: #000000;">
                                                <th  runat="server">
                                                </th>
                                                <th  runat="server">
                                                    ResourceID
                                                </th>
                                                <th  runat="server">
                                                    ResourceName
                                                </th>
                                                <th  runat="server">
                                                    ResourceValue
                                                </th>
                                                <th  runat="server">
                                                    Language
                                                </th>
                                                <th  runat="server">
                                                    Languages_Groups
                                                </th>
                                            </tr>
                                            <tr id="itemPlaceholder"  runat="server">
                                            </tr>
                                        </table>
                                    </td>
                                </tr>
                                <tr  runat="server">
                                    <td  runat="server" style="text-align: center; background-color: #CCCCCC; font-family: Verdana, Arial, Helvetica, sans-serif;
                                        color: #000000">
                                        <asp:DataPager ID="DataPager1" runat="server">
                                            <Fields>
                                                <asp:NextPreviousPagerField ButtonType="Button" ShowFirstPageButton="True" ShowLastPageButton="True" />
                                            </Fields>
                                        </asp:DataPager>
                                    </td>
                                </tr>
                            </table>
                        </LayoutTemplate>
                        <SelectedItemTemplate>
                            <tr style="background-color: #008A8C; font-weight: bold; color: #FFFFFF;">
                                <td>
                                    <asp:Label ID="ResourceIDLabel" runat="server" Text='<%# Bind("ResourceID") %>' />
                                </td>
                                <td>
                                    <asp:Button ID="DeleteButton" runat="server" CommandName="Delete" Text="Delete" />
                                    <asp:Button ID="EditButton" runat="server" CommandName="Edit" Text="Edit" />
                                </td>
                                <td>
                                    <asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />
                                    <td>
                                        <asp:Label ID="ResourceNameLabel" runat="server" Text='<%# Bind("ResourceName") %>' />
                                    </td>
                                    <td>
                                        <asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />
                                    </td>
                                    <td>
                                        <asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />
                                    </td>
                                </td>
                            </tr>
                        </SelectedItemTemplate>
                    </asp:ListView>
                    <asp:ObjectDataSource ID="ODSLanguageLabels" runat="server" DeleteMethod="DeleteLanglbls"

                        InsertMethod="InsertLangLBLs" SelectMethod="GetAllLangLBLs" TypeName="DAL+BLLangLabels"

                        UpdateMethod="UpdateLangLBLs">
                        <DeleteParameters>
                            <asp:Parameter Name="ResourceID" Type="Int32" />
                        </DeleteParameters>
                        <InsertParameters>
                            <asp:Parameter Name="langID" Type="Int32" />
                            <asp:Parameter Name="langGrpID" Type="Int32" />
                            <asp:Parameter Name="ResourceName" Type="String" />
                            <asp:Parameter Name="ResourceValue" Type="String" />
                        </InsertParameters>
                        <UpdateParameters>
                            <asp:Parameter Name="ResourceID" Type="Int32" />
                            <asp:Parameter Name="LangID" Type="Int32" />
                            <asp:Parameter Name="LangGrpID" Type="Int32" />
                            <asp:Parameter Name="ResourceName" Type="String" />
                            <asp:Parameter Name="ResourceValue" Type="String" />
                        </UpdateParameters>
                    </asp:ObjectDataSource>


please anyone could explain to me why the Bind in the table and read the parameter as its?
like what i understand is .. the Object data source Expect parameter from the user and he cant find the same param name idk why :(


please anyone could explain to me why the Bind in the table and read the parameter as its?
like what i understand is .. the Object data source Expect parameter from the user and he cant find the same param name idk why :(

推荐答案

From the code what I can make out is -
The Parameter names inside <updateparameters> and <insertparameters> tags should be same as that of the Parameter Name which you are binding in the label text.

例如-
You have a label
From the code what I can make out is -
The Parameter names inside <updateparameters> and <insertparameters> tags should be same as that of the Parameter Name which you are binding in the label text.

For Example -
You have a label
<asp:Label ID="ResourceValueLabel" runat="server" Text='<%# Bind("ResourceValue") %>' />


And the parameter inside the <updateparameters> and <insertparameters> tags for the same label is -


And the parameter inside the <updateparameters> and <insertparameters> tags for the same label is -

<asp:Parameter Name="ResourceValue" Type="String" />


So, from this it is clear that the parameter Name inside the "Bind()" method is same with the Name attribute value in Parameter tag, which is "ResourceValue".

So, assuming this logic you have some wrong value for some of the parameters.
They are-
1.


So, from this it is clear that the parameter Name inside the "Bind()" method is same with the Name attribute value in Parameter tag, which is "ResourceValue".

So, assuming this logic you have some wrong value for some of the parameters.
They are-
1.

<asp:Label ID="LanguageLabel" runat="server" Text='<%# Bind("Language.LangID") %>' />


for which you have parameter tag as -


for which you have parameter tag as -

<asp:Parameter Name="langID" Type="Int32" />


which should be like -


which should be like -

<asp:Parameter Name="Language.LangID" Type="Int32" />


还有

2.


And

2.

<asp:Label ID="Languages_GroupsLabel" runat="server" Text='<%# Bind("Languages_Groups.LangGrpID") %>' />


for which you have parameter tag as -


for which you have parameter tag as -

<asp:Parameter Name="LangGrpID" Type="Int32" />


which should be like -


which should be like -

<asp:Parameter Name="Languages_Groups.LangGrpID" Type="Int32" />



So, you have to make sure all the Parameter Names match.
Hope this solution helps.
Please let me know this helped you or not.
谢谢...



So, you have to make sure all the Parameter Names match.
Hope this solution helps.
Please let me know this helped you or not.
Thanks...


这篇关于列表视图和实体框架3.5让我发疯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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