Hi jordan,
I have created a sample which full fill your requirement you need to modify it according to your requirement
SQL
CREATE PROCEDURE GetColorNames
AS
BEGIN
DECLARE @ColorTable AS TABLE(ColorID INT,ColorName VARCHAR(50))
INSERT INTO @ColorTable VALUES(1,'Red')
INSERT INTO @ColorTable VALUES(2,'Blue')
INSERT INTO @ColorTable VALUES(3,'Black')
INSERT INTO @ColorTable VALUES(4,'Green')
INSERT INTO @ColorTable VALUES(5,'Yellow')
--Your Query of Table
SELECT ColorName FROM @ColorTable
END
GO
HTML
<div>
ColorPicker Gridview
<asp:GridView ID="gvColors" ShowHeader="false" runat="server" OnRowDataBound="gvColors_RowDataBound" />
</div>
C#
DataTable dtColorTable = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
string constr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(constr))
{
using (SqlCommand cmd = new SqlCommand("GetColorNames", con))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Connection = con;
sda.SelectCommand = cmd;
sda.Fill(dtColorTable);
gvColors.DataSource = dtColorTable;
gvColors.DataBind();
}
}
}
}
}
protected void gvColors_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[0].Style.Add("background-color", dtColorTable.Rows[e.Row.RowIndex]["ColorName"].ToString());
e.Row.Cells[0].Text = ""; // Text wont be visible.
e.Row.Cells[0].Width = 20; // Cells width.
e.Row.Cells[0].Height = 20; // Cells height.
}
}
VB.Net
Private dtColorTable As New DataTable()
Protected Sub Page_Load(sender As Object, e As EventArgs)
If Not Me.IsPostBack Then
Dim constr As String = ConfigurationManager.ConnectionStrings("constr").ConnectionString
Using con As New SqlConnection(constr)
Using cmd As New SqlCommand("GetColorNames", con)
Using sda As New SqlDataAdapter()
cmd.CommandType = CommandType.StoredProcedure
cmd.Connection = con
sda.SelectCommand = cmd
sda.Fill(dtColorTable)
gvColors.DataSource = dtColorTable
gvColors.DataBind()
End Using
End Using
End Using
End If
End Sub
Protected Sub gvColors_RowDataBound(sender As Object, e As GridViewRowEventArgs)
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(0).Style.Add("background-color", dtColorTable.Rows(e.Row.RowIndex)("ColorName").ToString())
e.Row.Cells(0).Text = ""
' Text wont be visible.
e.Row.Cells(0).Width = 20
' Cells width.
' Cells height.
e.Row.Cells(0).Height = 20
End If
End Sub
ScreenShot