none
Urgent: Problem in creating the Dynamic control for a dynamic listbox RRS feed

  • Question

  •  

    Hi All,

    I am creating listboxes dynamically based on the no.of folders available in one main folder

    Imagine i have folder named ASPNET, underneath of ASPNET i have 3 more folders like Controls, Server Controls, ... i want to create listboxes for these three subfolders and fill the list boxes with the content of subfolders(All subfolders contains notepad files).

    when i click on any of the listbox item, it should open me the particular text file.

    I have written the code for this, i am facing the problem with list box event handler. Below is the code:

     

    ASPX file:

    <%@ Register TagName="Cal" TagPrefix="Calender" Src="~/CalendarControl.ascx" %>

    <asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <script language="javascript">

     

    function SubmitPage()

    {

    document.form1.hdnList.value = document.getElementById("lstTest").selectedIndex;

    document.form1.submit();

    }

     

    </script>

    <table>

    <tr>

    <td nowrap>

    <asp:Label ID="DateLabel" Text="Date" runat="server"></asp:Label>

    </td>

    <td>

    <Calender:Cal ID="CalenderCtrl" runat="server" />

    </td>

    <td>

    <asp:Label ID="ReleaseLabel" Text="Release" runat="server"></asp:Label>

    </td>

    <td>

    <asp:DropDownList ID="ReleaseDropDownList" runat="server">

    <asp:ListItem Text="Gen II 7.3.1" Value="GenII7.3.1"></asp:ListItem>

    <asp:ListItem Text="Gen II CCAT" Value="GenIICCAT"></asp:ListItem>

    <asp:ListItem Text="Gen II 8.0" Value="GenII8.0"></asp:ListItem>

    </asp:DropDownList>

    </td>

    <td>

    <asp:Label ID="PhaseLabel" Text="Phase" runat="server"></asp:Label>

    </td>

    <td>

    <asp:DropDownList ID="PhaseDropDownList" runat="server">

    <asp:ListItem Text="Integrated QA" Value="IntegratedQA"></asp:ListItem>

    <asp:ListItem Text="Pre QA System Testing" Value="PreQASystemTesting"></asp:ListItem>

    <asp:ListItem Text="Syntel Int Testing" Value="SyntelIntTesting"></asp:ListItem>

    </asp:DropDownList>

    </td>

    <td>

    <asp:Button ID="SearchButton" Text="Search" runat="server" OnClick="SearchButton_Click" />

    </td>

    </tr>

    <tr>

    <td colspan="7" align="center">

    <asp:Label ID="Label2" Text="OR" runat="server"></asp:Label></td>

    </tr>

     

    <tr>

    <td colspan="7">

    <asp:Label ID="Label1" Text="Select Path to look for the specific Report" runat="server"></asp:Label><br />

    <input type="file" runat="server" id="fDocument" style="width: 410px" dir="rtl"/><asp:Button ID="ViewButton" OnClick="ViewButton_Click" Height="20px" Text="View Report" runat="server" />

    </td>

    </tr>

    <tr>

    <td colspan="10"><hr style="COLOR: black"/>

    <asp:Label ID="lblErrorMsg" runat="server"></asp:Label>

    <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" /><br />

    </tr>

    <tr>

    <td colspan="10"><br />

    <asp:ListBox ID="lstBox1" AutoPostBack="true" runat="server" OnSelectedIndexChanged="lstBox1_SelectedIndexChanged"></asp:ListBox>

    <asp:PlaceHolder ID="PlaceHolder1" runat="server">

    </asp:PlaceHolder>

    </td>

    </tr>

    </table>

    </asp:Content>

    CS File:

    protected void SearchButton_Click(object sender, EventArgs e)

    {

    try

    {

    string[] abc = Directory.GetDirectories("C:\\Reporting\\" + ((TextBox)CalenderCtrl.FindControl("txtDate")).Text.ToString() + "\\" + ReleaseDropDownList.SelectedItem.Text.ToString() + "\\" + PhaseDropDownList.SelectedItem.Text.ToString());

    //string[] abc = Directory.GetDirectories(strBaseUrl);

    lblErrorMsg.Text = string.Empty;

    lblErrorMsg.Visible = false;

    foreach (string a in abc)

    {

    DirectoryInfo dir = new DirectoryInfo(a);

    int i = 1;

    FileInfo[] fInfo = dir.GetFiles("*.rdl");if (fInfo.Length != 0)

    {

    Label lblHead = new Label();

    lblHead.ID = dir.Name;

    lblHead.Text = dir.Name;

    lblHead.Style.Add("color", "blue");

    lblHead.Style.Add("font-weight", "bold");

    lblHead.Style.Add("font-size", "14pt");lblHead.Attributes.Add("runat", "server");

    PlaceHolder1.Controls.Add(lblHead);

    ListBox lstBox = new ListBox();

    lstBox.ID = dir.Name;

    ListBox lst = new ListBox();

    lst.ID = (lstBox + i.ToString());

    Literal MyBreak = new Literal();MyBreak.Text = "<br/>";

    PlaceHolder1.Controls.Add(MyBreak);

    foreach (FileInfo f in dir.GetFiles("*.rdl"))

    {

    lstBox.Items.Add(f.Name);

    lstBox.Style.Add("color", "green");

    lstBox.Style.Add("font-size", "11pt");

    lstBox.Attributes.Add("runat", "server");

    //AutoPostBack set at control level property

    lstBox.AutoPostBack = true;

     

    //lstBox.Attributes.Add("AutoPostBack", "true");

    //lstBox.Attributes.Add("OnSelectedIndexChanged", "lstBox1_SelectedIndexChanged");

    //lstBox.SelectedIndexChanged += new EventHandler(lstBox1_SelectedIndexChanged);

    lstBox.SelectedIndexChanged += new EventHandler(lstBox_SelectedIndexChanged);

     

    this.PlaceHolder1.Controls.Add(lstBox);

    }

    Literal MyBreak2 = new Literal();MyBreak2.Text = "<br/>";

    PlaceHolder1.Controls.Add(MyBreak2);

    }

    }

    }

    catch (Exception ex)

    {

    lblErrorMsg.Visible = true;lblErrorMsg.Text = "No Data available with the selected criteria";

    }

    }

     

    Please look into my code and let me know the problem.

     

    Thanks,

    SR.

    Monday, February 11, 2008 6:09 PM

All replies