标签: objectdatasource

在ObjectDataSource上使用selection属性而不是'SelectMethod'?

我正在使用多个ObjectDataSources来填充FormView中的ComboBox字段.FormView有点通用,因为它的外观因其类别而异.

该类别在网页的网址中定义.我想创建一个类来过滤类别并公开几个属性,可以用来填充ComboBox字段.

问题是,默认的ObjectDataSource只有一个属性'SelectMethod'来检索数据.我希望创建这个类,它不是方法,而是包含数据的属性.

是不是在某种程度上,仍然可以将属性分配给'SelectMethod'(或类似的)?使用其他方法更好吗?

谢谢.

c# asp.net objectdatasource

3
推荐指数
1
解决办法
1103
查看次数

如何以编程方式更改ObjectDataSource的SelectMethod?

假设我有一个给定的ObjectDataSource,这个objectdatasource"SelectMethod"属性被设置为类Project的"GetProjectsByUsername"并接受一个参数.

 <asp:ObjectDataSource ID="GetProjectsDataSource" runat="server" SelectMethod="GetProjectsByUsername"
    TypeName="BusinessLayer.Project">
    <SelectParameters>
        <asp:ControlParameter ControlID="hiddenUsername" Name="username" PropertyName="Value"
            Type="String" />
    </SelectParameters>
</asp:ObjectDataSource>
Run Code Online (Sandbox Code Playgroud)

现在,是否可以将此ObjectDataSource的SelectMethod属性更改为在OnInit方法期间接受两个参数的方法?例如

MethodName:GetProjectByUsernameDeptCd()
参数:Username,DepartmentCode

我想通过用户角色更改select方法.我试图搜索SO和互联网,但似乎我没有运气.无论如何我想做的事情如下:

if(Role is Admin)
使用在ASPX中声明的默认SelectMethod和Parameters
else
将SelectMethod更改为"GetProjectByUsernameDeptCd"
设置parameter1 = value1
设置parameter2 = value2

或者我在想是否还有其他更好的方法可以做到这一点.

谢谢你,最诚挚的问候,Sherwin

c# asp.net objectdatasource

3
推荐指数
1
解决办法
1万
查看次数

ObjectDataSource 选择方法无法“看到”任何其他控件的值

我什至不知道如何清楚地说明这一点,而且代码太多,无法全部粘贴在这里。

让我从一般描述开始,也许它会敲响警钟。我有一个使用 ObjectDataSource 的 DataGrid。ObjectDataSource 使用 SelectMethod 调用另一个方法,因为需要两个日期选择器来过滤结果。

但是,当 SelectMethod 触发时,日期选择器始终为空。

一个相关的问题是需要一个按钮来使 ObjectDataSource 选择并使用两个根本不起作用的日期选择器值。就好像 ObjectDataSource 不咨询 GridView 以获取起始索引等。

如果有人知道类似这种设置的示例(GridView、Date 控件、按钮、ObjectDataSource),那就太好了。

编辑:这是代码。

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">

   <asp:Label ID="Label39" CssClass="txtSelect" runat="server" Text="Start Date" />
   <cc1:datepicker ID="startDatePicker" runat="server" Width="70px" PaneWidth="150px" SelectedDate="1/1/2000">
      <panetablestyle bordercolor="#707070" borderwidth="1px" borderstyle="Solid" />
      <paneheaderstyle backcolor="#0099FF" />
      <titlestyle forecolor="White" font-bold="true" />
      <nextprevmonthstyle forecolor="White" font-bold="true" />
      <nextprevyearstyle forecolor="#E0E0E0" font-bold="true" />
      <dayheaderstyle backcolor="#E8E8E8" />
      <todaystyle backcolor="#FFFFCC" forecolor="#000000" font-underline="false" bordercolor="#FFCC99" />
      <alternatemonthstyle backcolor="#F0F0F0" forecolor="#707070" font-underline="false" />
      <monthstyle backcolor="" forecolor="#000000" font-underline="false" />
   </cc1:datepicker>

   <asp:Label ID="Label5" …
Run Code Online (Sandbox Code Playgroud)

asp.net gridview objectdatasource

3
推荐指数
1
解决办法
3809
查看次数

ObjectDataSource分页 - > GridView中没有显示数据

我有一个objectdatasource和gridview配置如下所示(使用VS2008 w/.NET3.5):

    <asp:ObjectDataSource ID="odsMainData" runat="server" EnablePaging="True" OldValuesParameterFormatString="original_{0}"
        SelectMethod="GetMainData" TypeName="ErrorViewer.Model.ErrorViewModel" 
        SelectCountMethod="CountMainData">
        <SelectParameters>
            <asp:Parameter Name="maximumRows" Type="Int32" />
            <asp:Parameter Name="startRowIndex" Type="Int32" />
        </SelectParameters>
    </asp:ObjectDataSource>
    <asp:GridView ID="grdMainData" runat="server" AllowPaging="True"             DataSourceID="odsMainData" PageSize="15" AllowSorting="True">
    </asp:GridView>
Run Code Online (Sandbox Code Playgroud)

gridview或数据源的代码中没有事件处理程序或其他代码

因此底层类"ErrorViewModel"中有方法:public DataTable GetMainData(){var dt = provider.MainData(); myMainData = dt; 返回; }

    public DataTable GetMainData(int maximumRows, int startRowIndex)
    {
        var dt = provider.MainData();
        myMainData = dt;
        return dt;
    }

    public long CountMainData()
    {
        var count = provider.GetMainDataCount();
        return count;
    }

    public long CountMainData(int maximumRows, int startRowIndex)
    {
        var count = CountMainData(); …
Run Code Online (Sandbox Code Playgroud)

.net paging gridview objectdatasource

3
推荐指数
1
解决办法
1393
查看次数

将 Linq 用于 ObjectDataSource:如何使用 ToShortTimeString 转换日期时间?

我正在使用 ObjectDataSource 访问业务类并尝试生成对用户有意义的输出。返回值描述了一个类(如课堂和教学,而不是软件)。我想将课程时间显示为这样的范围:“9:00 AM - 10:00 AM”。

这是我用来提取数据的 Linq 查询:

return classQuery.Select(p => new SelectClassData
                              {
                                   ClassID = p.ClassID,
                                   Title = p.Title,
                                   StartDate = p.StartDate.ToShortDateString(),
                                   EndDate = p.EndDate.ToShortDateString(),
                                   TimeOfClass =
                                   p.StartDate.ToShortTimeString() + " - " +
                                                       p.EndDate.ToShortTimeString()
                               }).ToList();
Run Code Online (Sandbox Code Playgroud)

如您所见,我在开始和结束日期中对开始和结束时间进行了编码,即使它们可能位于不同的日期。

当我执行此代码时,我得到:

“无法将表达式 'p.EndDate.ToShortTimeString()' 转换为 SQL,并且无法将其视为本地表达式。”

我知道我正在投影结果,但是,作为 Linq 的新手,我假设对 ToShortTimeString 的 C# 调用发生在投影之后。谁能帮我弄清楚如何获得我正在寻找的字符串?

c# linq objectdatasource

2
推荐指数
1
解决办法
2344
查看次数

ObjectDataSource插入方法

我有一个ObjectDataSource,我绑定到DetailsView控件.我有一个在业务层(调用数据层)中编写的insert方法,一切正常......直到我想在insert方法触发之前做其他事情.在进入我的业务层之前,我需要访问fileupload控件.所以我在DetailsView上连接了一个ItemCommand事件 - 它接收了事件,我可以用FileUpload控件做我需要的就好了.在那种情况下,我在业务层中调用insert方法 - 与ObjectDataSource控件中指定的方法相同.但是Insert方法会触发两次!在考虑了这一点后,我意识到这是预期的行为 - 它从ItemCommand事件调用时被触发一次,而第二次从ObjectDataSource InsertMethod触发.

我以为我可以简单地从ObjectDataSource中删除InsertMethod属性以消除该方法的双重攻击,但是当我这样做时,我收到此错误:

除非指定了InsertMethod,否则ObjectDataSource'objStudentDetails'不支持插入.

那么有什么办法可以告诉ObjectDataSource不要激活方法吗?请参阅以下代码简化代码:

<asp:DetailsView ID="dtvStudentDetails" 
  runat="server" 
  AutoGenerateRows="False" 
  DataSourceID="objStudentDetails"
  OnItemCommand="dtvStudentDetails_ItemCommand">
   :
   :
</asp:DetailsView>


<asp:ObjectDataSource ID="objStudentDetails" 
  runat="server" 
  TypeName="AIMLibrary.BLL.Students" 
  SelectMethod="GetStudentDetails" 
  UpdateMethod="UpdateStudent">         
    :
    :
</asp:ObjectDataSource>


public static Int32 InsertStudent(Int32 studentId, String firstName, String lastName, String employer, String phone, String email, String address, String city, String state, String zip, String dob, String cardImagePath)
{
  StudentDetails record = new StudentDetails(firstName, lastName, employer, phone, email, address, city, state, zip, dob, cardImagePath);
  StudentsProvider provider = new StudentsProvider();
  return provider.InsertStudent(record);  //actual …
Run Code Online (Sandbox Code Playgroud)

asp.net objectdatasource

2
推荐指数
1
解决办法
8128
查看次数

错误:ObjectContext实例已被释放,不能再用于需要连接的操作

我在C#中使用asp.net和EF 4.

我有一个关联的DetailsView ObjectDataSource.

<asp:ObjectDataSource ID="uxEntityDataSourceAuthors" runat="server" 
        SelectMethod="GetAuthors" 
        TypeName="WebProject.Web.Cms.AdminCms.Sections.CmsContents.ContentInformation">
    </asp:ObjectDataSource>
Run Code Online (Sandbox Code Playgroud)

这个方法的代码:


    public IEnumerable<CmsAuthor> GetAuthors()
    {
    if (Roles.IsUserInRole("CMS-AUTHOR"))
    {
    using (CmsConnectionStringEntityDataModel context = new CmsConnectionStringEntityDataModel())
    {
                            // Display all Authors for specific logged-in User.
                            // Get Guid for current logged-in User.
                            MembershipUser myLoggedinUser = Membership.GetUser();
                            Guid myUserGuid = (Guid)myLoggedinUser.ProviderUserKey;
                            // Get list of Authors filtering my current logged-in User.
                            var myAuthorsForAuthor = from a in context.CmsAuthors
                                                     where a.UserId == myUserGuid
                                                     orderby a.LastName ascending
                                                     select a;
                            return myAuthorsForAuthor.AsEnumerable();
                        }
                    }
                    return …
Run Code Online (Sandbox Code Playgroud)

c# linq-to-entities entity-framework objectdatasource entity-framework-4

2
推荐指数
1
解决办法
6073
查看次数

如何在aspx标记中将IEnumerable绑定到Repeater?

我想将所有已定义的路由输出到页面上而不需要任何代码,因此我需要RouteTable.Routes在标记中绑定到Repeater.我该怎么做 - <asp:Repeater>只有DataSourceID标记中的值,而不是DataSource.我假设我需要声明一个DataSource RouteTable.Routes,然后将它的ID提供给Repeater,但我该怎么办呢?

同样,我需要一个没有任何代码隐藏的解决方案,只需要声明.

我正在使用asp.net 4.0(不是MVC)

asp.net repeater datasource objectdatasource

2
推荐指数
1
解决办法
2909
查看次数

InvalidOperationException:ObjectDataSource找不到具有参数的非泛型方法:

我正在尝试为本地ASP.NET页面编写ObjectDataSource代码.

阅读MSDN上的帮助文件总是让我摸不着头脑,想知道他们究竟会暗示什么.例如,我不确定我的TypeName应该是什么(尽管该链接有一个有趣的例子).

一旦我掌握了基础工作,我就会冒险进入更深的水域.

我的*.aspx文件的第一行包含我的定义:

<%@ Page Title="Reporter" Language="C#" MasterPageFile="~/local.Master"
    AutoEventWireup="true" CodeBehind="Reporter.aspx.cs"
    Inherits="AcpServiceNS.Reporter" %>
Run Code Online (Sandbox Code Playgroud)

在该页面中,我有TextBox控件名为txtStartDatetxtEndDate和一个编号命名DropDownList控件的ddlStartTime,ddlEndTime,ddlAction,ddlFilter1,和ddlFilter2.

我还有以下ObjectDataSource:

<asp:ObjectDataSource ID="dsReport" runat="server"
     SelectMethod="GetData"
     TypeName="System.Data.DataTable"
     ConvertNullToDBNull="True" >
  <SelectParameters>
    <asp:ControlParameter ControlID="txtStartDate" Name="startDate" PropertyName="Text" Type="String" DefaultValue="" />
    <asp:ControlParameter ControlID="ddlStartTime" Name="startTime" PropertyName="Text" Type="String" DefaultValue="" />
    <asp:ControlParameter ControlID="txtEndDate" Name="endDate" PropertyName="Text" Type="String" DefaultValue="" />
    <asp:ControlParameter ControlID="ddlEndTime" Name="endTime" PropertyName="Text" Type="String" DefaultValue="" />
    <asp:ControlParameter ControlID="ddlAction" Name="action1" PropertyName="Text" Type="String" DefaultValue="" />
    <asp:ControlParameter ControlID="ddlFilter1" …
Run Code Online (Sandbox Code Playgroud)

c# asp.net gridview objectdatasource

2
推荐指数
1
解决办法
2万
查看次数

使用MVC的ASP.Net Gridview控件

我要求在ASP.Net MVC中使用ASP.Net Grdview控件.现在我需要处理表单提交动作.我正在使用Objectdatasource来填充我的网格.现在,当我提交时,我需要拥有我的网格数据的当前状态,其中包括已选中状态的复选框.

asp.net-mvc gridview objectdatasource

1
推荐指数
1
解决办法
4万
查看次数