如何在MVC3中过滤gridview?

时间:2012-07-29 06:32:24

标签: asp.net-mvc-3 c#-4.0

每当我选择名称为.........的资源名称过滤器时,我在数据和下拉列表数据中都有gridview。 如何在控制器中编写代码?

我的控制器代码


public List<BugTracker_DataHelper> GeGridView()
         {
             var modelList = new List<BugTracker_DataHelper>();
             using (SqlConnection conn = new SqlConnection(@"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MvcBugTracker;Data Source=SSDEV6\SQLEXPRESS"))
             {
                 conn.Open();
                 SqlCommand dCmd = new SqlCommand("Select * from Resources", conn);
                 SqlDataAdapter da = new SqlDataAdapter(dCmd);
                 DataSet ds = new DataSet();
                 da.Fill(ds);
                 conn.Close();
                 for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
                 {
                     var model = new BugTracker_DataHelper();
                     model.ResourceID = Convert.ToInt16(ds.Tables[0].Rows[i]["ResourceID"]);
                     model.ResourceName = ds.Tables[0].Rows[i]["ResourceName"].ToString();
                     model.EmployeEmailID = ds.Tables[0].Rows[i]["EmailID"].ToString();
                     //model.status = ds.Tables[0].Rows[i]["Status"].ToString();
                     modelList.Add(model);
                 }
             }
             return modelList;
         }
         [AcceptVerbs(HttpVerbs.Post)]
         public ActionResult Grids(FormCollection collection,string ResourceName,int ResourceId)
         {
             return View();

         }

我的ModelCode


<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<IEnumerable<Gridview_BugTracker.Models.BugTracker_DataHelper>>" %>

<!DOCTYPE html>
<html>
<head runat="server">
    <link href="../../Content/GridStyle.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

    <title>Grids</title>
</head>
<body>
    <div>  
            <%: Html.DropDownList("ResourceID", (SelectList)ViewBag.ResourceID, "--Select Project--")%>
            <%: Html.ValidationMessage("ResourceID")%>  

            <%: Html.DropDownList("ResourceName", (SelectList)ViewBag.ResourceName, "--Select Project--")%>
            <%: Html.ValidationMessage("ResourceName")%>                        

                 <%       
                         var grid = new WebGrid(source: Model, defaultSort: "ResourceName", rowsPerPage: 3);
                         using (Html.BeginForm())
                         { %>                            
                            <div id="grid">
                            <%:grid.GetHtml(
                             tableStyle: "listing-border", headerStyle: "gridhead", footerStyle: "paging", rowStyle: "td-dark", alternatingRowStyle: "td-light",                            
                             columns:grid.Columns(                             
                            grid.Column("ResourceID"),
                            grid.Column("ResourceName"),
                            grid.Column("EmployeEmailID"),
                            grid.Column(
                            header: "",
                            style: "text-align-center",
                            format: (item) => Html.ActionLink("Edit", "Edit", new { ResourceID = item.ResourceID }))
                            ))%>
                            </div>
                            <%} %>         
    </div>
</body>
</html>

如何在控制器代码中写入..  请任何人帮助我

0 个答案:

没有答案