Bind Accrodian Dynamically
<html><head><Title>Dynamically bind Accrodian</title>
</head>
<body>
<tr style="vertical-align: top;">
<td valign="top" style="width: 5%;">
</td>
<td valign="top" style="width: 90%;" align="center">
<cc1:Accordion ID="Accordion1" runat="server" CssClass="accordion" Width="100%" HeaderCssClass="accordionHeader"
Height="100%" HeaderSelectedCssClass="accordionHeaderSelected" ContentCssClass="accordionContent">
</cc1:Accordion>
</td>
<td valign="top" style="width: 5%;">
</td>
</tr>
</head>
</body>
void bindData()
{
dt = new DataTable();
cmd = new SqlCommand("selectEachCust_TablesID", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@MainID", MainID);
con.Open();
da = new SqlDataAdapter(cmd);
da.Fill(dt);
con.Close();
if (dt.Rows.Count > 0)
{
bindAccordian(dt);
}
}
void bindAccordian(DataTable dt1)
{
int i = 0;
for (int j = 0; j < dt1.Columns.Count; j++)
{
if ((dt1.Rows[0][j].ToString()!="") && (Convert.ToInt64(dt1.Rows[0][j].ToString()) > 0))
{
AccordionPane p1 = new AccordionPane();
p1.Style.Add("overflow", "scroll");
//p1.Style.Add("Height", "100%");
p1.ID = "AccordionPane" + i;
Label lblHeader = new Label();
lblHeader.ID = "lblHeader" + i;
HiddenField hdnFld_tblName = new HiddenField();
hdnFld_tblName.ID = "hdnFld_tblName" + i;
if (dt1.Columns.Count > 1 && (tablename == "Sales" || tablename == "Service"))
{
if (j == 0)
{
lblHeader.Text = "BSO Sales Order";
hdnFld_tblName.Value = "tblBsoSalesOrder";
}
else if (j == 1)
{
lblHeader.Text = "Billing Address";
hdnFld_tblName.Value = "tblBsoBillingAddress";
}
else if (j == 2)
{
lblHeader.Text = "Delivery Address";
hdnFld_tblName.Value = "tblBsoDeliveryAddress";
}
else if (j == 3)
{
lblHeader.Text = "Product Details";
hdnFld_tblName.Value = "tblBsoProducts";
}
else if (j == 4)
{
lblHeader.Text = "Spare Details";
hdnFld_tblName.Value = "tblBsoSpares";
}
else if (j == 5)
{
lblHeader.Text = "Charges";
hdnFld_tblName.Value = "tblBsoCharges";
}
}
else
{
if (j == 0 && tablename == "AMC")
{
lblHeader.Text = "AMC Details";
hdnFld_tblName.Value = "tblAmc";
}
if (j == 1 && tablename == "AMC")
{
lblHeader.Text = "All AMC Details";
hdnFld_tblName.Value = "tblAmcDetails";
}
else if (j == 0 && tablename == "Query")
{
lblHeader.Text = "Query Details";
hdnFld_tblName.Value = "tblQuery";
}
}
p1.HeaderContainer.Controls.Add(lblHeader);
DataTable dt2 = new DataTable();
cmd = new SqlCommand("selectEachTableDetails", con);
cmd.CommandType = CommandType.StoredProcedure;
if (j != 3 && j != 4)
cmd.Parameters.AddWithValue("@MainID", dt1.Rows[0][j].ToString());
else
cmd.Parameters.AddWithValue("@MainID", MainID);
cmd.Parameters.AddWithValue("@TableName", hdnFld_tblName.Value.ToString());
con.Open();
da = new SqlDataAdapter(cmd);
da.Fill(dt2);
con.Close();
if (hdnFld_tblName.Value == "tblBsoProducts")
{
dt3 = dt2;
grv_Product.DataSource = dt2;
grv_Product.DataBind();
grv_Product.Visible = true;
p1.ContentContainer.Controls.Add(grv_Product);
}
else if (hdnFld_tblName.Value == "tblBsoSpares")
{
dt4 = dt2;
grv_Spare.DataSource = dt2;
grv_Spare.DataBind();
grv_Spare.Visible = true;
p1.ContentContainer.Controls.Add(grv_Spare);
}
else if (dt2.Rows.Count < 2)
{
dt6 = dt2;
GridView grid_AmcNew = new GridView();
grid_AmcNew.DataSource = dt2;
grid_AmcNew.DataBind();
grid_AmcNew.Visible = true;
CssClass_GridView(grid_AmcNew);
p1.ContentContainer.Controls.Add(grid_AmcNew);
}
Accordion1.Panes.Add(p1);
i++;
}
}
No comments:
Post a Comment