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="id" >
<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="#404040" 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(query444, conn);
conn.Open();
reader444 = cmd333.ExecuteReader();
if (reader444.HasRows)
{
DataList1.DataSource = reader444;
DataList1.DataBind();
}
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(query4, conn);
reader4 = cmd3.ExecuteReader();
if (reader4.HasRows)
{
DataList2.DataSource = reader4;
DataList2.DataBind();
}
else
{
exx1.Visible = false;
exx2.Visible = false;
exx3.Visible = false;
}
reader4.Close();
conn.Close();
}
}
protected void Page_Load(object 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(Session["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.DataSource = ds;
DataList3.DataBind();
}
protected void CommandBtn2_Click(object sender, CommandEventArgs e)
{
string[] strPartss = rname.Split('_');
features.Visible = true;
extras.Visible = true;
string str = e.CommandArgument.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(object sender, EventArgs e)
{
menucat.Text += DataList2.Items.Count.ToString() + "<br />";
}
Please help me i have stuck in to strange kind of situation.