hemant Rawat

hemant Rawat

  • NA
  • 33
  • 22.7k

grid view inside datalist

Feb 14 2018 1:08 PM
here is my aspx code:
 
<asp:DataList ID="DataList1" runat="server" style="text-align: center" OnItemDataBound="DataList1_ItemDataBound">
<ItemTemplate>
<div style="text-align: justify">
<asp:Label ID="Label7" runat="server" style="text-align: center" Text="Invoice"></asp:Label>
<br />
DATE:
<asp:Label ID="Label3" runat="server" Text='<%#Eval("tdate") %>'></asp:Label>
<br />
<asp:Image ID="Image1" runat="server" Height="86px" Width="97px" />
<br />
ORDER ID:<asp:Label ID="Label4" runat="server" Text='<%#Eval("orderid") %>'></asp:Label>
<br />
</div>
<asp:GridView ID="GridView1" runat="server" Height="131px" Width="504px" AutoGenerateColumns="False" >
<Columns>
<asp:BoundField DataField="itemname" HeaderText="itemname" SortExpression="itemname" />
<asp:BoundField DataField="itemcost" HeaderText="itemcost" SortExpression="itemcost" />
<asp:BoundField DataField="qty" HeaderText="qty" SortExpression="qty" />
<asp:BoundField DataField="subtotal" HeaderText="subtotal" SortExpression="subtotal" />
<asp:BoundField DataField="cname" HeaderText="cname" SortExpression="cname" />
</Columns>
</asp:GridView>
TOTAL:<asp:Label ID="Label5" runat="server" text='<%#Eval("total") %>'></asp:Label>
<br />
<br />
SIGNATURE:<asp:Label ID="Label8" runat="server" Text="Canteen Authority"></asp:Label>
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="GENERATE PDF" />
</ItemTemplate>
</asp:DataList>
 
here is .cs code:
 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using iTextSharp.text;
using System.IO;
using iTextSharp.text.html.simpleparser;
using iTextSharp.text.pdf;
using System.Configuration;
namespace yummyproject
{
public partial class myorder : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["mycon"].ToString());
string sid;
string orderid;
protected void Page_Load(object sender, EventArgs e)
{
if (Session["Username"] != null)
{
sid = Session["Username"].ToString();
string sql = "SELECT orderid,tdate,total from order1 where sid='" + sid + "' and deliverystatus='notyet'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
da.Fill(dt);
DataList1.DataSource = dt;
DataList1.DataBind();
string qry = "SELECT orderid,tdate,total from order1 where sid='" + sid + "' and deliverystatus='notyet'";
SqlCommand cmd = new SqlCommand(qry, con);
SqlDataReader rdr = cmd.ExecuteReader();
while (rdr.Read())
{
orderid = rdr["orderid"].ToString();
}
}
else
{
Response.Write("nothing");
}
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
GridView GridView1 = (GridView)e.Item.FindControl("GridView1");
BindGrid(GridView1, DataList1.DataKeys[e.Item.ItemIndex].ToString());
}
private void BindGrid(GridView GridView, string CusState)
{
string sql ="SELECT * from orderdetail where orderid='" + orderid + "'";
SqlDataAdapter da = new SqlDataAdapter(sql, con);
DataTable dt = new DataTable();
da.Fill(dt);
GridView.DataSource = dt;
GridView.DataBind();
}
}
}
 
im getting an error
 
 

Answers (1)