Click here to Skip to main content
15,898,222 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hello,

i have 5 columns in table and those are shown on grid view by checking some conditions.

but at run time i want to add another column in grid view that is not in the table....

how it can b done
Posted
Comments
Kaushik Saha from Kolkata,India 21-Jul-12 4:32am    
Give some code snippets.
Tejas Vaishnav 21-Jul-12 5:35am    
please give your design code as well as binding code with table description
Pradeep_kaushik 21-Jul-12 6:05am    
i gave the description in solution window now can u pls help me
Kaushik Saha from Kolkata,India 21-Jul-12 7:20am    
this is not right position of updation of a problem.give some c# code snippets how you fill your gridview.which will be balance field data?
Pradeep_kaushik 21-Jul-12 7:27am    
i explain in solution section on solution 3

SqlDataAdapter da=new SqlDataAdapter("select SNO,DATE,PNAME,QUANT,RATE,TOTAL from BILL1 where CNAME='"+Label1.Text+"' and DATE between '" + dt1.ToShortDateString() + "' and '" + dt2.ToShortDateString() + "'",con);
DataSet ds=new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
con.Close();

/////////////
con.Open();
SqlCommand cmd = new SqlCommand("select SNO,DATE,PNAME,QUANT,RATE,TOTAL from BILL1 where CNAME='" + Label1.Text + "' and DATE between '" + dt1.ToShortDateString() + "' and '" + dt2.ToShortDateString() + "'", con);

SqlDataReader dr1 = cmd.ExecuteReader();
while (dr1.Read())
{


a += Convert.ToDecimal(dr1["TOTAL"].ToString());
// SqlConnection con1 = new SqlConnection(ConfigurationManager.ConnectionStrings["order"].ConnectionString);
// SqlCommand cmd1 = new SqlCommand("update BILL1 set BALANCE=" + a + "", con1);
// con1.Open();
// cmd1.ExecuteNonQuery();
// con1.Close();

}
Label5.Text = a.ToString();
Label6.Text = a.ToString();
con.Close();

}

protected void Button1_Click(object sender, EventArgs e)
{
Page.RegisterStartupScript("PrintPage", "<script language='javascript'>window.print()</script>");
}

protected void Button2_Click(object sender, EventArgs e)
{
Response.Redirect("GENERATEBILL2.aspx");
}

1 solution

this is my design code for grid view

XML
<asp:GridView ID="GridView1" runat="server" xmlns:asp="#unknown" Width="453px">


                       </asp:GridView>




i have to generate a bill of between dates for a particular customer

sno.----cname--prod-----quant---price---total---date
1--------ram----lock-------12------02----24----05/07/2012
36-------raju---lock-------10------50----500----17/07/2012

now i have to add one more column in my gridview on bill page named BALANCE

n that contain value like
this is for a particular customer

total-----Balance
50----------50
20----------70
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900