Dear Sir,
please help me sir to display hidden gridview cell values in a label
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="test.aspx.cs" Inherits="ReadTxtFile.test" %>
<meta http-equiv="refresh" content="1">
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:Label ID="label2" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label3" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label4" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label5" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label6" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label7" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label8" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<asp:Label ID="label9" runat="server" Text="Label" Style="font-weight: 700; background-color: #CCFF99;"></asp:Label>
<div style="width: 903px">
<h4 style="width: 366px; text-align: center; height: 21px; background-color: #FFFFFF;">
EQMS Generation Data :
<asp:Label ID="label1" runat="server" Text="Label"></asp:Label></h4>
<asp:GridView ID="GridView1" runat="server" CellPadding="3" AutoGenerateColumns="False"
OnDataBound="OnDataBound" OnRowDataBound="GridView1_RowDataBound" Style="text-align: center;
font-weight: 700;" Width="504px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None"
BorderWidth="1px" Height="100px">
<Columns>
<asp:BoundField DataField="e1" HeaderText="yyyy/mm/ss" ItemStyle-Width="200" Visible="true">
<ItemStyle Width="200px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e2" HeaderText="COD" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e3" HeaderText="mg/l" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e4" HeaderText="BOD" ItemStyle-Width="30" Visible="false">
<ItemStyle Width="30px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e5" HeaderText="mg/l" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e6" HeaderText="TSS" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e7" HeaderText="mg/l" ItemStyle-Width="30" Visible="true">
<ItemStyle Width="30px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e8" HeaderText="pH" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e9" HeaderText="units" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e10" HeaderText="Oil & Grease" ItemStyle-Width="30" Visible="false">
<ItemStyle Width="30px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e11" HeaderText="mg/l" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e12" HeaderText="Conductivity" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e13" HeaderText="uS/cm" ItemStyle-Width="30" Visible="true">
<ItemStyle Width="30px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e14" HeaderText="Flow" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e15" HeaderText="m3/hr" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e16" HeaderText="Id" ItemStyle-Width="30" Visible="false">
<ItemStyle Width="30px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e17" HeaderText="C" ItemStyle-Width="150" Visible="true">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField DataField="e18" HeaderText="Temperature" ItemStyle-Width="150" Visible="false">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
</form>
</body>
</html>
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace ReadTxtFile
{
public partial class test : System.Web.UI.Page
{
SqlConnection con;
SqlCommand cmd;
SqlTransaction tran;
string connStr = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
SqlCommand com;
protected void Page_Load(object sender, EventArgs e)
{
label1.Text = DateTime.Now.ToString();
con = new SqlConnection(@"Data Source=(localdb)\Projects;Initial Catalog=munpldta;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;");
cmd = new SqlCommand();
cmd.Connection = con;
//string filePath = @"C:\Users\Arjun\Desktop\Test.csv";
string filePath = @"D:\eqms\eqms.csv";
string csvData = " ";
using (var stream = File.Open(filePath, FileMode.Open))
{
using (var reader = new StreamReader(stream))
{
//Read the contents of CSV file.
csvData = reader.ReadToEnd();
}
}
//Create a DataTable.
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[]
{
new DataColumn("e1", typeof(string)),
new DataColumn("e2", typeof(string)),
new DataColumn("e3",typeof(string)),
new DataColumn("e4", typeof(string)),
new DataColumn("e5", typeof(string)),
new DataColumn("e6", typeof(string)),
new DataColumn("e7", typeof(string)),
new DataColumn("e8", typeof(string)),
new DataColumn("e9" ,typeof(string)),
new DataColumn("e10", typeof(string)),
new DataColumn("e11", typeof(string)),
new DataColumn("e12",typeof(string)),
new DataColumn("e13", typeof(string)),
new DataColumn("e14", typeof(string)),
new DataColumn("e15", typeof(string)),
new DataColumn("e16", typeof(string)),
new DataColumn("e17", typeof(string)),
new DataColumn("e18", typeof(string))
});
// dt.Rows.Add("UoM");
int j = 0;
foreach (string row in csvData.Split('\n'))
{
if (j > 1)
{
if (!string.IsNullOrEmpty(row))
{
int i = 0;
DataRow dr = dt.NewRow();
foreach (string cell in row.Split(','))
{
dr[i] = cell;
i++;
}
dt.Rows.Add(dr);
}
}
j++;
}
//string slno = null;
GridView1.DataSource = dt;
GridView1.DataBind();
foreach (GridViewRow g1 in GridView1.Rows)
{
// SqlCommand com =new SqlCommand("UPDATE eqms SET e1 = '" + g1.Cells[0].Text + "', e2 = '" + g1.Cells[2].Text + "',e3 ='" + g1.Cells[4].Text + "', e4 ='" + g1.Cells[6].Text + "' ,e5 ='" + g1.Cells[8].Text + "', e6 = '" + g1.Cells[10].Text + "', e7 = '" + g1.Cells[12].Text + "', e8 = '" + g1.Cells[14].Text + "', e9 = '" + g1.Cells[16].Text + "' where id='1'", con);
// SqlCommand com = new SqlCommand("insert into eqms(e1,e2,e3,e4,e5,e6,e7,e8,e9) values ('" + g1.Cells[0].Text + "','" + g1.Cells[2].Text + "','" + g1.Cells[4].Text + "','" + g1.Cells[6].Text + "','" + g1.Cells[8].Text + "','" + g1.Cells[10].Text + "','" + g1.Cells[12].Text + "','" + g1.Cells[14].Text + "','" + g1.Cells[16].Text + "')", con);
//slno = e1;
label2.Text = g1.Cells[2].Text;
label3.Text = g1.Cells[4].Text;
label4.Text = g1.Cells[2].Text;
label5.Text = g1.Cells[4].Text;
label6.Text = g1.Cells[2].Text;
label7.Text = g1.Cells[4].Text;
label8.Text = g1.Cells[2].Text;
label9.Text = g1.Cells[4].Text;
// con.Open();
//com.ExecuteNonQuery();
// con.Close();
}
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
e.Row.Cells[1].Visible = false;
}
protected void OnDataBound(object sender, EventArgs e)
{
GridViewRow row = new GridViewRow(0, 0, DataControlRowType.Header, DataControlRowState.Normal);
TableHeaderCell cell = new TableHeaderCell();
cell.Text = "Date/Time";
// cell.ColumnSpan = 2;
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "COD";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "BOD";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "TSS";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "pH";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "Oil & Grease";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "Conductivity";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "Flow";
row.Controls.Add(cell);
cell = new TableHeaderCell();
// cell.ColumnSpan = 2;
cell.Text = "Temperature";
row.Controls.Add(cell);
row.BackColor = ColorTranslator.FromHtml("#3AC0F2");
GridView1.HeaderRow.Parent.Controls.AddAt(0, row);
}
}
}