DataList no Accessible

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • flashleo
    New Member
    • Apr 2009
    • 4

    DataList no Accessible

    A strange problem i am facing i bind DataList on link button Argument Event.

    <asp:DataList id="DataList2" runat="server" horizontalalign ="Left" repeatdirection ="Horizontal " repeatcolumns=" 3" DataKeyField="i d" >
    <ItemTemplate >
    <asp:checkbox id="chkItem" runat="server" value='<%# Eval("extras")% >' /><asp:label id="Label5" runat="server"> <%# " " +Eval("extras") %></asp:label>
    </itemtemplate>
    <itemstyle width="120px" forecolor="#404 040" horizontalalign ="Left" font-names="Arial" font-size="10pt" />
    </asp:DataList>

    /////////////////////////////////////

    private void LoadUserControl ()
    {
    if (typee == "Other")
    {




    string query444 = "Select * from extras where mid=" + foodid + " AND psizes=0 AND type=1";
    SqlCommand cmd333 = new SqlCommand(quer y444, conn);

    conn.Open();

    reader444 = cmd333.ExecuteR eader();
    if (reader444.HasR ows)
    {
    DataList1.DataS ource = reader444;
    DataList1.DataB ind();

    }
    else
    {
    ex1.Visible = false;
    ex2.Visible = false;
    ex3.Visible = false;
    }
    reader444.Close ();

    string query4 = "Select * from extras where mid=" + foodid + " AND psizes=0 AND type=2";
    SqlCommand cmd3 = new SqlCommand(quer y4, conn);
    reader4 = cmd3.ExecuteRea der();
    if (reader4.HasRow s)
    {
    DataList2.DataS ource = reader4;
    DataList2.DataB ind();

    }
    else
    {
    exx1.Visible = false;
    exx2.Visible = false;
    exx3.Visible = false;
    }
    reader4.Close() ;
    conn.Close();


    }
    }



    protected void Page_Load(objec t sender, EventArgs e)
    {
    conn.Close();

    rname = Session["rname"].ToString();
    restid= Session["restid"].ToString();
    menuu= Session["menuu"].ToString();
    mdetail= Session["mdetail"].ToString();
    int mid1 = int.Parse(Sessi on["mid"].ToString());
    menucat.Text = menuu;
    Label1.Text = mdetail;
    SqlDataAdapter myCommand = new SqlDataAdapter( "Select * from other where restid LIKE '%" + restid + "%' AND menucat LIKE '%" + menuu + "' AND mid LIKE '%"+mid1+"%'" , conn);

    DataSet ds = new DataSet();
    myCommand.Fill( ds);

    DataList3.DataS ource = ds;
    DataList3.DataB ind();


    }
    protected void CommandBtn2_Cli ck(object sender, CommandEventArg s e)
    {


    string[] strPartss = rname.Split('_' );


    features.Visibl e = true;
    extras.Visible = true;


    string str = e.CommandArgume nt.ToString();

    string[] strParts = str.Split('_');

    price = strParts[0].ToString();
    price = price.Trim();
    foodname = strParts[1].ToString();
    foodname = foodname.Trim() ;
    foodid = strParts[2].ToString();
    foodid = foodid.Trim();
    typee = strParts[3].ToString();
    typee = typee.Trim();
    string fooddesc = strParts[4].ToString();

    Label3.Text = foodname;
    Label2.Text = fooddesc;

    string fsizes = foodname + " (£" + price + ")";
    sizes.Items.Add (fsizes);

    LoadUserControl ();
    }



    When press submit and use Datalist2.Items .Count it gives 0 while there are items in datalist. Datalist2 is not accessible after bind. While other datalists on same page giving perfect Items count. Here is button code:




    protected void Button1_Click(o bject sender, EventArgs e)
    {

    menucat.Text += DataList2.Items .Count.ToString () + "<br />";


    }


    Please help me i have stuck in to strange kind of situation.
Working...