如何将复选框更改为是或否值

时间:2019-02-20 08:44:02

标签: c# sql asp.net

我在动态gridview中有一列数据类型为bit。要运行,我进入了aspx页面中的该列复选框。如何将复选框更改为某种样式或字体。使用asp.net,c#

<asp:GridView ID="gvedition" runat="server" AutoGenerateColumns="True" CssClass="table table-responsive"
                    OnRowDataBound="gvedition_RowDataBound">

在C#中进行gridview绑定

protected void bindedition()
        {
            SqlConnection con = new SqlConnection(str);
            DataTable dt = new DataTable();
            SqlDataAdapter da = new SqlDataAdapter();
            try
            {
                con.Open();
                da = new SqlDataAdapter("usp_edition_comparison", con);
                da.Fill(dt);
                gvedition.DataSource = dt;
                gvedition.DataBind();

            }
            catch (Exception ex)
            {
                ex.Message.ToString();
            }
            finally
            {
                con.Close();
            }
        }

但是我这样 please click to view image

如何将复选框更改为某种字体。 我需要如何使用fontawesome网站图标?

1 个答案:

答案 0 :(得分:0)

您可以尝试以下过程,它可能会对您有所帮助。

  1. 由于无法更改DataTable的列类型,因此您需要克隆dataTable。

  2. 更改要更改的相应列的列类型。

  3. 根据需要更新要更改的列中的值。

    try
        {
            DataTable dt = new DataTable();
            dt.Columns.AddRange(new DataColumn[4] { new DataColumn("Id", typeof(int)),
                        new DataColumn("Name", typeof(string)),
                        new DataColumn("Country",typeof(string)),
                        new DataColumn("Status",typeof(bool))
            });
            dt.Rows.Add(1, "John Hammond", "United States", true);
            dt.Rows.Add(2, "Mudassar Khan", "India", false);
            dt.Rows.Add(3, "Suzanne Mathews", "France", false);
            dt.Rows.Add(4, "Robert Schidner", "Russia", true);
    
            #region Cloned
            DataTable dtCloned = dt.Clone();
            dtCloned.Columns[3].DataType = typeof(string);
            foreach (DataRow row in dt.Rows)
            {
                dtCloned.ImportRow(row);
            }
    
            foreach (DataRow row in dtCloned.Rows)
            {
                row[3] = (row[3].ToString().ToLower() == "true") ? "Active" : "InActive";
            }
            #endregion
    
            GridView1.DataSource = dtCloned;
            GridView1.DataBind();
        }
        catch (Exception ex)
        {
    
            throw;
        }
    
相关问题