• GridView with SqlDataSource


    <asp:Button ID="btn" runat="server" OnClick="btnView_Click" CausesValidation="true" Text="Search" />  

    <asp:gridview id="gv"  allowpaging="true" allowsorting="true" runat="server" autogeneratecolumns="False" datakeynames="StudentID"  datasourceid="SqlDataSource1" >
    <Columns>
            <asp:BoundField DataField="IDString" HeaderText="Student ID" SortExpression="IDString" />
    </Columns>
    </asp:gridview>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:************* %>"
                CancelSelectOnNullParameter="false" SelectCommand="Select=@*****"
                OnSelecting="on_Selecting">
                <SelectParameters>
                    <asp:Parameter Name="*****" />
               </SelectParameters>
    </asp:SqlDataSource>

       

    code
     1  protected void on_Selecting(object sender, SqlDataSourceSelectingEventArgs e)
     2     {
     3         string strFilter = GetFilterStr();
     4         SqlDataSource1.FilterExpression = strFilter;
     5     }
     6 
     7     private string GetFilterStr()
     8     {
     9         StringBuilder strFilter = new StringBuilder();
    10         strFilter.Append("1=1");
    11 
    12         strFilter.AppendFormat(" and (XXXXX='{0}')", XXXX);
    13     }
    14 
    15 
    16 
    17     protected void btnView_Click(object sender, EventArgs e)
    18     {
    19         SqlDataSource1.SelectParameters["SchoolID"].DefaultValue = SchoolDropDownList1.SelectedValue.ToString();
    20         gv.DataBind();
    21     }
    22 
    23 
  • 相关阅读:
    [ SharePoint ADFS 开发部署系列 (一)]
    [ Office 365 开发系列 ] Graph Service
    [ Office 365 开发系列 ] 身份认证
    [ Office 365 开发系列 ] 开发模式分析
    [ Office 365 开发系列 ] 前言
    Debian安装Chrome
    SharePoint 常用操作杂谈
    SharePoint Managed Metadata 使用总结
    SharePoint PerformancePoint开发实例
    node使用mysql报错
  • 原文地址:https://www.cnblogs.com/sandy_liao/p/1764528.html
Copyright © 2020-2023  润新知