For example, I have a source(Id, Name) with some records. I want to bind it to GridView
. But, I want to format each record before add it to GridView
, for example, I want to write prefix "test" to all the record where field is "Name". I heared that I need to use onRowDataBound
event, but I cant understand how.
问问题
161 次
3 回答
0
First if you want to make little format on the data you are displaying, you can do this easily in your .aspx
using Eval
function
to search on Google use this asp.net eval format
Second for your example check this question : Add prefix of http:// or https:// with Eval value
于 2013-02-26T10:42:36.690 回答
0
Use the DataFormatString in your gridview column. Ex:
<asp:BoundField DataField="name" DataFormatString="test_{0}" HeaderText="name"
HtmlEncode="False" SortExpression="name" />
This will result in:
test_YourData
于 2013-02-26T11:34:28.153 回答
0
Well you can do that by capturing the binding event.
YourGrid.DataBound += YourGrid_RowDataBound
void YourGrid_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[1].Text = "test_" + e.Row.Cells[1].Text;
}
}
于 2013-02-26T12:10:21.257 回答