<div>Hi, everyone</div> <div></div> <div></div> <div>There's a function in Controller, for Preparing some value, and it's called somewhere:</div> <div> </div> <div> <div>
</div> <div></div> <div>Notice Codes Above:</div> <div></div> <div>
pdtsGrid.Column(
columnName: "wb_Type",
header: "产品类型", format: (item) => nvcPdtsTypeParam[(string)item.wb_Type],
style: "FontAutoCol"
),</div> <div></div> <div></div> <div>the field 'wb_Type' in database is tinyint</div> <div></div> <div>When I view web page, the place of bold style codes show a Error message: </div> <div></div> <div> [ Cant't change byte
type to string... ]</div> <div></div> <div></div> <div></div> <div>So, how to fix it if not modify the filed type in database? Thx very much</div> <div></div> <div></div>
richard20427...
Member
94 Points
58 Posts
What's up? Error on Formatting Webgrid-Column
May 18, 2011 09:25 AM|LINK
<div>private NameValueCollection GetPdtsType() { NameValueCollection nvcPdtsTypeParam = new NameValueCollection(); nvcPdtsTypeParam.Add("1","aaa"); nvcPdtsTypeParam.Add("2", "bbb"); nvcPdtsTypeParam.Add("3", "ccc"); nvcPdtsTypeParam.Add("4", "ddd"); return nvcPdtsTypeParam; }</div></div> </div> <div> </div> <div>at the top of view , I get the NameValueCollection object:</div> <div></div> <div> <div>@ { NameValueCollection nvcPdtsTypeParam = new NameValueCollection(); if (TempData["nvcPdtsTypeParam"] != null) { nvcPdtsTypeParam = TempData["nvcPdtsTypeParam"] as NameValueCollection; } }</div> </div> <div></div> <div></div> <div>then I want to custom data in my WebGrid:</div> <div></div> <div><div id="divGrid"> @pdtsGrid.GetHtml( tableStyle: "TblRow", alternatingRowStyle: "AltRow", headerStyle: "HeaderRow", columns: pdtsGrid.Columns( pdtsGrid.Column( columnName: "wb_Name", header: "产品名称", format: (item) => Html.ActionLink((string)item.wb_Name, "PdtsDetail", new { id = item.wb_Guid }), style: "FstColMargin" ), //pdtsGrid.Column("wb_Type", "产品类型"), pdtsGrid.Column( columnName: "wb_Type", header: "产品类型", format: (item) => nvcPdtsTypeParam[(string)item.wb_Type], style: "FontAutoCol" ), pdtsGrid.Column(columnName: "wb_Url1", header: "网 址 一", style: "Fontx12Col"), ) ) </div></div> <div></div> <div>Notice Codes Above:</div> <div></div> <div> pdtsGrid.Column(columnName: "wb_Type",
header: "产品类型",
format: (item) => nvcPdtsTypeParam[(string)item.wb_Type],
style: "FontAutoCol"
),</div> <div></div> <div></div> <div>the field 'wb_Type' in database is tinyint</div> <div></div> <div>When I view web page, the place of bold style codes show a Error message: </div> <div></div> <div> [ Cant't change byte type to string... ]</div> <div></div> <div></div> <div></div> <div>So, how to fix it if not modify the filed type in database? Thx very much</div> <div></div> <div></div>
raduenuca
All-Star
24675 Points
4250 Posts
Re: What's up? Error on Formatting Webgrid-Column
May 18, 2011 10:57 AM|LINK
I think you should motify it like this:
nvcPdtsTypeParam[item.wb_Type].ToString()
Radu Enuca | Blog
richard20427...
Member
94 Points
58 Posts
Re: What's up? Error on Formatting Webgrid-Column
May 18, 2011 01:06 PM|LINK
thank u ~~
changed as:
format: (item) => nvcPdtsTypeParam[item.wb_Type.ToString()].ToString()