2012-07-27 5 views
3

지난 며칠 동안 나는 MVC와 협력 해왔다. ...MVC3에서 Grid에 데이터를 바인딩하는 방법은 무엇입니까?

그리드에서 많은 데이터를 보여줘야한다. 나는이 모든 것을 테이블에 표시 할 수 있었지만 나의 요구 사항은 바인딩하는 것이다. 그것은 JQuery와 격자 또는 Webgrid ...

내가이 기대 아이디어와 제안을 수행하는 방법을 모르는이와 붙어입니다 ....

컨트롤러에

 public ActionResult Index() 
    { 
     var bugList = GetList(); 
     return View(bugList); 
    } 
    public List<ProjectModel> GetList() 
    { 
     var modelList = new List<ProjectModel>(); 
     using (SqlConnection conn = new SqlConnection("Data Source=LMIT-0039;Initial Catalog=BugTracker;Integrated Security=True")) 
     { 
      conn.Open(); 
      SqlCommand dCmd = new SqlCommand("Select * from Projects", 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 ProjectModel(); 
       model.ID = Convert.ToInt16(ds.Tables[0].Rows[i]["ProjectID"]); 
       model.projectName = ds.Tables[0].Rows[i]["projectName"].ToString(); 
       model.Description = ds.Tables[0].Rows[i]["Description"].ToString(); 
       model.status = ds.Tables[0].Rows[i]["Status"].ToString(); 
       modelList.Add(model); 
      } 
     } 
     return modelList; 
    } 

보기 (ASPX)

<table> 
<thead align="center"> 
<tr class="BoldCenterAlignHeaderStyle">  

    <th> 
     ProjectName 
    </th>  
    <th> 
     Status 
    </th> 
    <th align="center"> 
    Edit 
    </th>   
</tr> 
</thead> 
    <% foreach (var item in Model) { %> 
     <tr>   
     <td> 
     <%:Html.LabelForModel(item.projectName) %> 
     </td>  
     <td> 
     <%:Html.LabelForModel(item.status) %> 
     </td> 
     <td align="center"> 
     <a href="<%:Url.Action("Edit",new{id=item.ID}) %>" class="Edit"><img src="../../Content/edit.gif" height="8px"/></a> 
      <%--<%:Html.ActionLink("Edit", "Edit", new { id = item.ID })%> --%>   
     <%-- <a href="<%:Url.Action("Delete",new{id=item.ID}) %>" class="Delete"><img src="../../Content/delete.gif" height="8px" /></a>--%> 
     </td>   
     </tr> 
    <%} %> 

내가 그렇게 할 수 그렇지 않으면 어떻게 하나가 제발 도움이 될 수 있습니다 자신에게 그리드에 데이터를 표시하는 방법을 테이블에 페이징을 할 수 있다면 ... . 어느 사람이 나를 어떻게 설명하는지.

+0

% % <와 "@를 {"대체하고 <내 grind.GetHtml 포장 @anilkumar aspx 페이지 – SoftwareNerd

답변

1

예 :

@model IEnumerable<ProjectModel> 
@{ 
    var grid = new WebGrid(
    source: Model, 
    rowsPerPage: 4); 
} 
@grid.GetHtml(
    tableStyle: "grid", 
    headerStyle: "header", 
    rowStyle: "row", 
    footerStyle: "footer", 
    alternatingRowStyle: "altRow", 
    columns: grid.Columns (
     grid.Column("projectName"), 
     grid.Column("ProjectID") 
)) 
+0

에서이 작업을 수행하는 방법에 대해 설명합니다. "@ 모델"을 "<% @ Page"선언으로 바꾸는 것을 잊지 마십시오. – SoftwareNerd

+0

에서이 작업을 수행하는 방법을 aspx 페이지 –

1

이것을 위해 Webgrid를 사용할 수 있습니다. webgrid

http://yassershaikh.com/webgrid-paging-with-pager-method-in-razor-mvc/

http://www.mikesdotnetting.com/Article/154/Looking-At-The-WebMatrix-WebGrid http://msdn.microsoft.com/en-us/magazine/hh288075.aspx

페이징을 webgrid하는

소개 작동 webgrid 방법은 다음과

는 이해하기위한 몇 가지 링크입니다

고급 희망

Webgrid

http://www.dotnetcurry.com/ShowArticle.aspx?ID=615의 (효율적인) 페이징이 도움이 ..! webgrid에 대한

관련 문제