2012-08-09 1 views
0
<div id="grid" class="ajaxGrid"> 
    @{ 
     var grid = new WebGrid(list, rowsPerPage: 8, canPage: true, canSort: true, ajaxUpdateContainerId: "grid"); 
    } 

    @grid.GetHtml(
     tableStyle: "grid", 
     headerStyle: "head", 
     alternatingRowStyle: "alt", 
     mode: WebGridPagerModes.All, 
     numericLinksCount: 10, 
     firstText: "First", 
     previousText: "Prev", 
     nextText: "Next", 
     lastText: "Last", 
     columns: grid.Columns(
     grid.Column((string)(@<text>@item.Value</text>),format: (item) => Html.ActionLink(((string)item.Text), "Search", "Home", new { id = item.Value }, new { @class = "clickable" })))) 
</div> 

프로그램을 실행할 때 webgrid 뷰가 표시되지 않습니다. 코드의 오류는 무엇입니까 ?? 누구든지 나를 위해 대답을 게시 할 수 있습니까 ??웹 그리드 뷰에서 동적 열 이름을 설정하는 방법

답변

0

System.Web.Helpers.WebGrid.Column 

그래서 내가 생성자에 잘못된 인수를 전달하는 의미, 당신의 코드가 작동 할 수있는 방법이 표시되지 않는 다음과 같은 생성자에게

Column(string, string, System.Func<dynamic,object>, string, bool) 

있습니다. 첫 번째 인수로

당신은

(string)(@<text>@item.Value</text>)

를 할당하지만 문자열이어야한다, 그래서 람다 표현은 불가능합니다. 나를

@grid.GetHtml(
     tableStyle: "grid", 
     headerStyle: "head", 
     alternatingRowStyle: "alt", 
     mode: WebGridPagerModes.All, 
     numericLinksCount: 10, 
     firstText: "First", 
     previousText: "Prev", 
     nextText: "Next", 
     lastText: "Last", 
       columns: grid.Columns(grid.Column(header: "some column header", format: (item) => Html.ActionLink(((string)item.Text), "Index", "Home", new { id = item.Id }, new { @class = "clickable" })))) 

그래서, 당신이 열 생성자에게 올바른 방법을 사용 확인을 위해 작동하는 코드이다

.

또한 좋은 주제 http://tinyurl.com/9n39mgv

+0

에 대한 스레드하지만 난 형의 문자열로 변환하고 필요한 모든 생성자를 수행 한은 (item.Value @ @) (문자열)를 사용하여 캐릭터 .. 지금 무슨 오류입니다 .. 형식 변환 작업을하지 않습니다 ?? –

+0

달성하려는 목표를 말해주십시오. 그것은 헤더 이름, 일반적으로 "Blah"와 같은 문자열 상수입니다. –

+0

헤더를 클릭하면 컨트롤러에 헤더 이름을 동적으로 보내야합니다. 다른 테이블의 데이터를로드 할 수 있도록 다른 데이터베이스가 데이터베이스에 있습니다. 다른 시간에 webgrid .. 그래서 다른 테이블에 대한 다른 헤더 이름을 사용해야합니다 .. 그래서 어떤 테이블 값을 gridview 및 헤더 이름으로 데이터 정렬로드 할 수 있습니다 .. –

관련 문제