Create dynamic accordion pane and bind with varbinary data

create dynamic accordion pane and bind with varbinary data

Design page for VS2008

<asp:ToolkitScriptManager ID="ToolkitScriptManager1" runat="server">

        </asp:ToolkitScriptManager>

        <asp:Accordion ID="Dynamic" runat="server" SelectedIndex="0" HeaderCssClass="headerAccordion" ContentCssClass="contentAccordion">

        </asp:Accordion>

Design page for VS2010

<asp:ScriptManager ID="ScriptManager1" runat="server">

        </asp:ScriptManager>      

        <asp:Accordion ID="Dynamic" runat="server" SelectedIndex="0" HeaderCssClass="headerAccordion" ContentCssClass="contentAccordion">

        </asp:Accordion> 

Add below line for css within <title></title>

<link href="Styles/accordion.css" rel="stylesheet" type="text/css" />

(you will get at attachment)

Code Behind

Retrieve value and put at datatable like below

string sql1 = "select * from Admin_Package_Details where Pak_Type='" + b + "'";
SqlConnection con = new SqlConnection(GetConnectionString());
SqlCommand cmd = new SqlCommand(sql, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da.Fill(dt);

Now create dynamic accordion pane based on value with pane title

int i = 0;
for(i=0;i<dt.rows.count;i++)
{
    //create pane with unique id
    AjaxControlToolkit.AccordionPane pn;
    pn = new AjaxControlToolkit.AccordionPane();
    pn.ID = "Pane" + i;
    //create title and bind
    Label lbTitle;
    lbTitle = new Label();
    for (int p = 0; p < dt.Rows.Count; p++)
    {
        lbTitle.Text = b.ToString() + " " + "(" + dt.Rows[p][2].ToString() + "Days Package)";
    }
    //now add title at pane
    pn.HeaderContainer.Controls.Add(lbTitle);
    //add pane at accordion
    Dynamic.Panes.Add(pn);
    i++;
}

Now if you have to bind varbinary data at dynamic accordion then do like below. 

dt.Columns.Add("PackageDescriptionNew");
foreach (DataRow dr in dt.Rows)
{
    if (dr != null)
    {
        byte[] byt = (byte[])dr[3];
        string str;
        System.Text.ASCIIEncoding enc = new System.Text.ASCIIEncoding();
        str = enc.GetString(byt);
        dr[4] = str;
    }
} 

My varbinary content was at 4th column so dr[3] and I create one extra (column(dt.Columns.Add("PackageDescriptionNew");) which is dr[4].

Now create dynamic table where you can bind this value, like below.

(Namespace using System.Web.UI.HtmlControls;)

HtmlTable table1 = new HtmlTable();
HtmlTableRow row;
HtmlTableCell cell;
cell = new HtmlTableCell();
row = new HtmlTableRow();
cell.InnerHtml = dt.Rows[0][4].ToString();
row.Cells.Add(cell);
table1.Rows.Add(row); 

Now add this table at accordion pane like below. 

pn.ContentContainer.Controls.Add(table1); 

Now you can add print button like below.

Button print;
print = new Button();
print.Text = "Print";
print.Attributes.Add("onclick", "return printing()");
pn.ContentContainer.Controls.Add(print); 

Java script you have to add

<script language=javascript>
         function printing() {
             window.print(); 
         }
    </script> 

Now you can add link button with querystring like below

string a = lbTitle.Text;
string url = "querystring.aspx?";
url += "Item=" + a.ToString();
LinkButton lk;
lk=new LinkButton();
lk.Text="Booking";
lk.PostBackUrl = url;

add link button at accordion pane like below

pn.ContentContainer.Controls.Add(lk);

Next Recommended Reading Creating Dynamic Enums using C#