GridView中显示男和女

 (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") + "')");
        }
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值