GridView1 RowDataBound

2018-11-02 08:50:26来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Attributes.Add("onmouseover", "this.name=this.className;this.className='selrow';");
                e.Row.Attributes.Add("onmouseout", "this.className=this.name;");

                string BWFlag = DataBinder.Eval(e.Row.DataItem, "BWFlag").ToString();

                if(BWFlag == "B")
                {
                    e.Row.Cells[3].Text = "黑名单";
                }
                else
                {
                    e.Row.Cells[3].Text = "白名单";
                }
                //ModelBlackWhiteList model = row.DataItem as ModelBlackWhiteList;
                LinkButton lkImage = e.Row.FindControl("lkImage") as LinkButton;
                //Image imgCar = e.Row.FindControl("imgCar") as Image;
                object CarPicPath = DataBinder.Eval(e.Row.DataItem, "CarPicPath");
                if (CarPicPath != null)
                {
                    lkImage.PostBackUrl = "ShowImage.aspx?CarPicPath=" + System.Web.HttpUtility.HtmlEncode(CarPicPath.ToString());
                }
                else
                {
                    lkImage.PostBackUrl = "#";
                }
            }
        }

<asp:BoundField DataField="BWFlag" HeaderText="黑/白名单" />
<asp:TemplateField HeaderText="车牌图片" ItemStyle-Width="100px">
<ItemTemplate>
<asp:LinkButton ID="lkImage" runat="server" CommandArgument='<%#Eval("Id") %>' CommandName="ShowImg" CssClass="btnedit">
<asp:Image ID="imgCar" runat="server" Height="40" ImageUrl='<%#Eval("CarPicPath")%>'/>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>

 

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:C#.NET优化

下一篇:避免图片路径访问405,可以用图片控件来显示局部相对路径,不需