(1) GRIDVIEW里有个列是男1 女0,数据库存是1和0,怎么显示为男和女呢?
<asp:TemplateColumn HeaderText="性别">
<ItemTemplate>
<asp:Label runat="server" Text='<%# DataBinder.Eval(Container, "DataItem.Sex").ToString()="1"?"男":"女" %>' ID="SEX">
</asp:Label>
</ItemTemplate>
</asp:TemplateColumn>
(2)
在GRIDVIEW的第一列加个编号 编号规则就是 1、2、3、4、5。。。。。。
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Text = e.Row.DataItemIndex.ToString();
}
}
(3)
GridView中对一个字符型列进行格式化?
<%# DataBinder.Eval(Container.DataItem,"Field").ToString().Substring(0,5)%>
<asp:HyperLinkColumn HeaderText="sdf" DataNavigateUrlField="id" DataNavigateUrlFormatString="javascript:alert({0})" DataTextField="id" >
HtmlEncode="false"
(4)
删除前弹出确认对画框
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton l = (LinkButton)e.Row.FindControl("LinkButton1");
l.Attributes.Add("onclick", "javascript:return " +
"confirm('Are you sure you want to delete this record " +
DataBinder.Eval(e.Row.DataItem, "id") + "')");
}
}