如何在网格视图中创建动态行? [英] How to createdynamic Rows in a Grid View?
本文介绍了如何在网格视图中创建动态行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用动态行和列显示Gridview ..我怎么能得到这个...请帮助我
I want to display Gridview with Dynamic rows and column ..How can i achive this..please help me
推荐答案
public void BindOrders()
{
try
{
DataTable dtordernotobind = new DataTable();
objFeedRetPL.cstype = Request.QueryString["customertype"].ToString();
objFeedRetPL.statesno = Convert.ToInt32(Request.QueryString["state"].ToString());
objFeedRetPL.customername = Request.QueryString["customername"].ToString();
objFeedRetPL.fromdate = Convert.ToDateTime(Request.QueryString["fromdate"].ToString());
objFeedRetPL.todate = Convert.ToDateTime(Request.QueryString["todate"].ToString());
if (Request.QueryString["type"].ToString() == "1")
{
dtordernotobind = objFeedRetBAL.GetOrdernofalseReport(objFeedRetPL);
}
else
{
dtordernotobind = objFeedRetBAL.GetOrdernoTrueReport(objFeedRetPL);
}
if (dtordernotobind.Rows.Count > 0)
{
for (int i = 0; i < dtordernotobind.Rows.Count; i++)
{
string customertype, customername, ordertype, frieght, orderdate;
string orderno;
DataTable dtorderdetailstable = new DataTable();
objFeedRetPL.Orderno = dtordernotobind.Rows[i]["OrderNo"].ToString();
dtorderdetailstable = objFeedRetBAL.GetOrderTable(objFeedRetPL);
if (dtorderdetailstable.Rows.Count > 0)
{
orderno = dtorderdetailstable.Rows[0]["OrderNo"].ToString();
orderdate = dtorderdetailstable.Rows[0]["orderdate"].ToString();
customertype = dtorderdetailstable.Rows[0]["Customertype"].ToString();
customername = dtorderdetailstable.Rows[0]["Customername"].ToString();
ordertype = dtorderdetailstable.Rows[0]["Order Type"].ToString();
frieght = dtorderdetailstable.Rows[0]["freight"].ToString();
Table tbldynamic = new Table();
tbldynamic.BorderStyle = BorderStyle.Ridge;
tbldynamic.Width = 600;
TableCell tc = new TableCell();
TableRow tr = new TableRow();
Label lblorderno = new Label();
lblorderno.ID = "lblorderno" + i.ToString();
lblorderno.Text = "OrderNo:" + " ";
tc.Controls.Add(lblorderno);
Label lblordernodata = new Label();
lblordernodata.ID = "lblordernodata" + i.ToString();
lblordernodata.Text = orderno + " ";
tc.Controls.Add(lblordernodata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
Label lbldate = new Label();
lbldate.ID = "lbldate" + i.ToString();
lbldate.Text = "Date:" + " ";
tc.Controls.Add(lbldate);
Label lbldatedata = new Label();
lbldatedata.ID = "lbldatedata" + i.ToString();
lbldatedata.Text = orderdate + " ";
tc.Controls.Add(lbldatedata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
Label lblfreight = new Label();
lblfreight.ID = "lblFreight" + i.ToString();
lblfreight.Text = "Freight:" + " ";
tc.Controls.Add(lblfreight);
Label lblfreightdata = new Label();
lblfreightdata.ID = "lblfreightdata" + i.ToString();
lblfreightdata.Text = frieght + " ";
tc.Controls.Add(lblfreightdata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
tc = new TableCell();
tr = new TableRow();
Label lblcstype = new Label();
lblcstype.ID = "lblcstype" + i.ToString();
lblcstype.Text = "Customer Type:" + " ";
tc.Controls.Add(lblcstype);
Label lblcstypedata = new Label();
lblcstypedata.ID = "lblcstypedata" + i.ToString();
lblcstypedata.Text = customertype + " ";
tc.Controls.Add(lblcstypedata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
Label lblcsname = new Label();
lblcsname.ID = "lblcsname" + i.ToString();
lblcsname.Text = "Customer Name:" + " ";
tc.Controls.Add(lblcsname);
Label lblcsnamedata = new Label();
lblcsnamedata.ID = "lblcsnamedata" + i.ToString();
lblcsnamedata.Text = customername + " ";
tc.Controls.Add(lblcsnamedata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
Label lblordertype = new Label();
lblordertype.ID = "lblordertype" + i.ToString(); ;
lblordertype.Text = " Order Type:" + " ";
tc.Controls.Add(lblordertype);
Label lblordertypedata = new Label();
lblordertypedata.ID = "lblordertypedata" + i.ToString();
lblordertypedata.Text = ordertype + " ";
tc.Controls.Add(lblordertypedata);
tr.Cells.Add(tc);
tbldynamic.Rows.Add(tr);
DataTable dtorderdetails = new DataTable();
objFeedRetPL.Orderno = dtordernotobind.Rows[i]["OrderNo"].ToString();
objFeedRetPL.date = Convert.ToDateTime(dtorderdetailstable.Rows[0]["ordereddate"].ToString());
objFeedRetPL.statesno = Convert.ToInt32(dtordernotobind.Rows[0]["state"].ToString());
dtorderdetails = objFeedRetBAL.GetOrdersReport(objFeedRetPL);
GridView gvorderstally = new GridView();
gvorderstally.ID = "gvordertall" + dtordernotobind.Rows[i]["OrderNo"].ToString();
gvorderstally.Width = 600;
Label lblTotal = new Label();
Label lblwt = new Label();
BoundField FeedType = new BoundField();
FeedType.HeaderText = "FeedType";
FeedType.DataField = "Feedtype";
gvorderstally.Columns.Add(FeedType);
BoundField Bagtype = new BoundField();
Bagtype.HeaderText = "BagType";
Bagtype.DataField = "Bagtype";
gvorderstally.Columns.Add(Bagtype);
BoundField noofbags = new BoundField();
noofbags.HeaderText = "NoofBags";
noofbags.DataField = "noofbags";
gvorderstally.Columns.Add(noofbags);
BoundField rateperkg = new BoundField();
rateperkg.HeaderText = "Rate/Kg";
rateperkg.DataField = "rateperkg";
gvorderstally.Columns.Add(rateperkg);
BoundField totalamount = new BoundField();
totalamount.HeaderText = "Total Amount";
totalamount.DataField = "totalamount";
gvorderstally.Columns.Add(totalamount);
BoundField totalamountafterdiscount = new BoundField();
totalamountafterdiscount.HeaderText = "AfterDiscount";
totalamountafterdiscount.DataField = "AmountAfterDiscount";
gvorderstally.Columns.Add(totalamountafterdiscount);
gvorderstally.AutoGenerateColumns = false;
gvorderstally.ShowFooter = true;
gvorderstally.DataSource = dtorderdetails;
gvorderstally.DataBind();
divbirdtal.Controls.Add(tbldynamic);
divbirdtal.Controls.Add(gvorderstally);
divbirdtal.Controls.Add(lblTotal);
divbirdtal.Controls.Add(lblwt);
LiteralControl @break = default(LiteralControl);
@break = new LiteralControl("<br />");
divbirdtal.Controls.Add(@break);
LiteralControl @break1 = default(LiteralControl);
@break1 = new LiteralControl("<br />");
divbirdtal.Controls.Add(@break1);
GridViewRow footerRow = gvorderstally.FooterRow;
if (footerRow != null)
{
double totalSum = 0;
double totalamount1 = 0;
double afterdiscount = 0;
foreach (DataColumn c in dtorderdetails.Columns)
{
if (c.ColumnName.ToUpper() == "NOOFBAGS")
{
double sum = 0;
foreach (DataRow rw in dtorderdetails.Rows)
{
sum = sum + Convert.ToDouble(rw[c].ToString());
footerRow.Cells[dtorderdetails.Columns.IndexOf(c.ColumnName)].Text = sum.ToString();
}
totalSum = Convert.ToDouble(totalSum + sum);
totalSum = Convert.ToDouble(Math.Round(totalSum, 2));
}
if (c.ColumnName == "totalamount")
{
double sum1 = 0;
foreach (DataRow rw in dtorderdetails.Rows)
{
sum1 = sum1 + Convert.ToDouble(rw[c].ToString());
footerRow.Cells[dtorderdetails.Columns.IndexOf(c.ColumnName)].Text = sum1.ToString();
}
totalamount1 = Convert.ToDouble(totalSum + sum1);
totalamount1 = Convert.ToDouble(Math.Round(totalamount1, 2));
}
if (c.ColumnName == "AmountAfterDiscount")
{
double sum2 = 0;
foreach (DataRow rw in dtorderdetails.Rows)
{
sum2 = sum2+ Convert.ToDouble(rw[c].ToString());
//footerRow.Cells[dtorderdetails.Columns.IndexOf(c.ColumnName)].Text = sum2.ToString()+" + "+Convert.ToDouble(frieght).ToString()+" = ";
}
afterdiscount = Convert.ToDouble(sum2)+Convert.ToDouble(frieght);
afterdiscount = Convert.ToDouble(Math.Round(afterdiscount, 2));
if (Convert.ToDouble(frieght) != 0)
{
footerRow.Cells[dtorderdetails.Columns.IndexOf(c.ColumnName)].Text = sum2.ToString() + " + " + Convert.ToDouble(frieght).ToString() + " = " + afterdiscount;
}
else
{
footerRow.Cells[dtorderdetails.Columns.IndexOf(c.ColumnName)].Text = Convert.ToDouble(afterdiscount).ToString();
}
}
}
}
}
}
}
}
}
这篇关于如何在网格视图中创建动态行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文