Hi Waghmare,
Check this example. Now please take its reference and correct your code.
HTML
<asp:GridView ID="grdPurchaseDetails" runat="server" OnRowDataBound="grdPurchaseDetails_RowDataBound"
CssClass="table table-condensed table-striped" AutoGenerateColumns="false" ViewStateMode="Enabled"
HeaderStyle-CssClass="bg-success" EmptyDataText="No Products has been added."
ShowHeaderWhenEmpty="true">
<Columns>
<asp:TemplateField HeaderText="Edit" HeaderStyle-Width="5%" HeaderStyle-CssClass="bg-success gridHeaders">
<ItemTemplate>
<%-- <asp:LinkButton ID="btnEditProduct" runat="server" OnClick="btnEditProduct_Click"><span style="font-size:medium;color:maroon" class="glyphicon glyphicon-edit"></span></asp:LinkButton><%--<i class="fa fa-trash fa-2x"></i>--%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
ss
<asp:TemplateField HeaderText="ProductID" HeaderStyle-Width="25%" HeaderStyle-CssClass="hiddencol">
<ItemTemplate>
<asp:Label ID="lblProductIDGrid" runat="server" Text='<%#Eval("Product_ID") %>'></asp:Label>
</ItemTemplate>
<ItemStyle CssClass="hiddencol" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Remove" HeaderStyle-Width="5%" HeaderStyle-CssClass="bg-success gridHeaders">
<ItemTemplate>
<%-- <asp:LinkButton ID="lnkRemove" runat="server" OnClick="lnkRemove_Click"><span style="font-size:medium;color:red" class="glyphicon glyphicon-trash"></span></asp:LinkButton><%--<i class="fa fa-trash fa-2x"></i>--%>
</ItemTemplate>
<ItemStyle HorizontalAlign="Center" />
</asp:TemplateField>
</Columns>
</asp:GridView>
Namespaces
using System.Data;
using System.Drawing;
VB.Net
Imports System.Data
Imports System.Drawing
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[1] { new DataColumn("Product_ID", typeof(string)) });
dt.Rows.Add("1");
dt.Rows.Add("2");
dt.Rows.Add("3");
dt.Rows.Add("4");
dt.Rows.Add("5");
grdPurchaseDetails.DataSource = dt;
grdPurchaseDetails.DataBind();
}
}
protected void grdPurchaseDetails_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Height = 50;
if (e.Row.RowType == DataControlRowType.DataRow)
{
if (e.Row.RowIndex % 2 == 0)
{
e.Row.BackColor = Color.LightYellow;
}
else
{
e.Row.BackColor = Color.LightGray;
}
}
}
VB.Net
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
If Not Me.IsPostBack Then
Dim dt As DataTable = New DataTable()
dt.Columns.AddRange(New DataColumn(0) {New DataColumn("Product_ID", GetType(String))})
dt.Rows.Add("1")
dt.Rows.Add("2")
dt.Rows.Add("3")
dt.Rows.Add("4")
dt.Rows.Add("5")
grdPurchaseDetails.DataSource = dt
grdPurchaseDetails.DataBind()
End If
End Sub
Protected Sub grdPurchaseDetails_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
e.Row.Height = 50
If e.Row.RowType = DataControlRowType.DataRow Then
If e.Row.RowIndex Mod 2 = 0 Then
e.Row.BackColor = Color.LightYellow
Else
e.Row.BackColor = Color.LightGray
End If
End If
End Sub
Screenshot