GridView1 RowDataBound

 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>

 

posted @ 2018-11-02 10:47 hi-latolo 阅读(...) 评论(...) 编辑 收藏