开发者

GridView button with condition

I have a gridview with 3 columns Name,Surname,Change(ButtonField column) which is populated from an SqlDataReader with the following code

               SqlCommand sqlCommand = new SqlCommand("select * from Empl where userId ='" + userid + "'", sqlConnection);
            sqlConnection.Open();

            SqlDataReader reader = sqlCommand.ExecuteReader();

            GridView1.DataSource = reader;
            GridView1.DataBind();

In my database there are 4 colum开发者_如何学编程ns UserId,Name,Surname,Change(bit). How can i show the button change only when Change(bit) column is true inside the database?


You can do like..

<asp:TemplateField>
      <ItemTemplate>
         <asp:Button ID="btnChange" runat="server" Text="Change" 
              Visible='<%# (Boolean) Eval("Change") %>' />
      </ItemTemplate>
 </asp:TemplateField>

As you mentioned in the comment you are getting error on the above code, you try like...

Visible='<%# Convert.ToBoolean(Eval("Change")) == true ? true : false %>' 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜