扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
<form id="Form1" method="post" runat="server"> <asp:DataGrid id="DataGrid1" runat="server" AutoGenerateColumns="False" DataKeyField="EmployeeID"> <Columns> <asp:TemplateColumn> <ItemTemplate> <asp:CheckBox runat="server" ID="EmployeeCheckBox" /> </ItemTemplate> </asp:TemplateColumn> <asp:TemplateColumn> <ItemTemplate> <%# DataBinder.Eval(Container.DataItem, "LastName") %>, <%# DataBinder.Eval(Container.DataItem, "FirstName") %> </ItemTemplate> </asp:TemplateColumn> </Columns> </asp:DataGrid> <hr> <asp:Button id="Orders" runat="server" Text="View Orders"></asp:Button> <hr> <asp:DataGrid ID="DataGrid2" Runat="server" AutoGenerateColumns="True" /> </form> |
private void Page_Load(object sender, System.EventArgs e) { if(!Page.IsPostBack) { Database db = DatabaseFactory.CreateDatabase(); DBCommandWrapper dbCommandWrapper; using(dbCommandWrapper = db.GetSqlStringCommandWrapper(SELECT_EMPLOYEES)) { using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper)) { DataGrid1.DataSource = dataReader; DataGrid1.DataBind(); } } } } |
SELECT EmployeeID, FirstName, LastName FROM Employees WHERE EmployeeID IN (7, 4) |
SELECT count(*) AS Orders, E.FirstName, E.LastName FROM Orders O INNER JOIN Employees E ON O.EmployeeID = E.EmployeeID WHERE E.EmployeeID IN(SELECT Value FROM fn_Split(@employeeIDs, ',')) GROUP BY FirstName, LastName ORDER BY count(*) DESC |
private string GetCheckedEmployeeIDs() { String delimiter = String.Empty; StringBuilder employeeIDs = new StringBuilder(); for(int i = 0; i < DataGrid1.Items.Count; i++) { CheckBox checkbox; checkbox = DataGrid1.Items[i].FindControl("EmployeeCheckBox") as CheckBox; if(checkbox != null && checkbox.Checked == true) { employeeIDs.Append(delimiter + DataGrid1.DataKeys[i].ToString()) ; delimiter = ","; } } return employeeIDs.ToString(); } |
private void Orders_Click(object sender, System.EventArgs e) { string employeeIDs = GetCheckedEmployeeIDs(); Database db = DatabaseFactory.CreateDatabase(); DBCommandWrapper dbCommandWrapper; using(dbCommandWrapper = db.GetSqlStringCommandWrapper(SELECT_ORDERS)) { dbCommandWrapper.AddInParameter("@employeeIDs", DbType.String, employeeIDs); using (IDataReader dataReader = db.ExecuteReader(dbCommandWrapper)) { DataGrid2.DataSource = dataReader; DataGrid2.DataBind(); } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者