LinqDataSource类示例

时间:2011-09-23 00:02:54

标签: c# asp.net linq gridview linqdatasource

刚开始研究如何使用LinqDataSource进行GridView,我正在寻找更多关于如何设置数据源的示例。

我希望以后能够针对SharePoint列表使用它,但是现在我只是简单地介绍了一个可以从中检索数据并更新的类的详细示例。

以下是MS的示例类。我只是经过一个以上的例子,所以我更好地了解这是如何工作的。

一个已知可行的简单例子,它会更复杂

public class MovieLibrary
{
        string[] _availableGenres = { "Comedy", "Drama", "Romance" };

        public MovieLibrary()
        {
        }

        public string[] AvailableGenres
        {
            get
            {
                return _availableGenres;
            }
        }
    }

干杯

1 个答案:

答案 0 :(得分:0)

我正在使用带有SPGridView的LinqDataSource,这是我的代码。

      <SharePoint:SPGridView runat="server" ID="spgvUserTrainingLists" AutoGenerateColumns="false"
                                DataSourceID="linqDsEmployeeTrainingLists" DataKeyNames="RowId" OnRowDataBound="spgvUserTrainingLists_RowDataBound"
                                AllowSorting="true" AllowPaging="true" PageSize="15" AllowFiltering="true" FilteredDataSourcePropertyName="Where"
                                FilteredDataSourcePropertyFormat='{1} == "{0}"' FilterDataFields=",TrainingType,,Trainer,Status">
                                <Columns>
                                    <SharePoint:SPBoundField HeaderText="Ref #" SortExpression="RefNo" DataField="RefNo" />
                                    <SharePoint:SPBoundField HeaderText="Type" SortExpression="TrainingType" DataField="TrainingType" />
                                    <asp:TemplateField HeaderText="Training" SortExpression="TrainingTitle">
                                        <ItemTemplate>
                                            <asp:HyperLink ID="hlTrainingDetail" runat="server" Text='<%# Eval("TrainingTitle") %>'
                                                NavigateUrl="#" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <SharePoint:SPBoundField HeaderText="Trainer" SortExpression="Trainer" DataField="Trainer" />
                                    <SharePoint:SPBoundField HeaderText="Status" SortExpression="Status" DataField="Status" />
                                    <asp:TemplateField>
                                        <ItemTemplate>
                                            <asp:ImageButton ID="imgDelete" ImageUrl="~/_layouts/images/DELITEM.GIF" runat="server"
                                                UseSubmitBehaviour="false" CommandValue='<%# Eval("RowId") %>' OnClientClick="javascript:DeleteTraining(this);" />
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                </Columns>
                                <EmptyDataTemplate>
                                    No training yet.
                                </EmptyDataTemplate>
                            </SharePoint:SPGridView>
                            <SharePoint:SPGridViewPager ID="SPGridViewPager1" runat="server" GridViewId="spgvUserTrainingLists" />
                            <aspweb:LinqDataSource runat="server" ID="linqDsEmployeeTrainingLists" OnSelecting="linqDs_Selecting" />

在LinqDataSource中,选择事件是发生数据绑定的地方

protected void linqDs_Selecting(object sender, LinqDataSourceSelectEventArgs e)
    {
        object parameter = null;

        if (e.SelectParameters.TryGetValue("employee", out parameter))
        {
            e.Result = DefaultBLL.GetEmployeeTrainingLists(parameter.ToString());
        }
    }


Hope this help.