I have a datalist in which have a label that shows the datetime and have a grid inside the datalist .The problem is that i get the desire format of time (for e.g 1:48 AM) and data inside the grid only on odd no of record for example 1 3 5 7 records are correct and 2 4 6 7 show the empty record in the grid and the label also show the incorrect format(10/21/2015 1:48:20 AM). Here is the code. onitemDataBound event

protected void dataListOrder_ItemDataBound(object sender, DataListItemEventArgs e)
        {
            if(e.Item.ItemType==ListItemType.Item)
            {

                Label date = e.Item.FindControl("lblOrderDate") as Label;
                string[] datesplit = date.Text.Split(' ');
                string time =string.Concat(datesplit[1]+" "+datesplit[2]);
                date.Text = time.ToString();

                int order_ID = Convert.ToInt32((e.Item.FindControl("orderid") as HiddenField).Value);
                GridView innerDataList = e.Item.FindControl("datalistOrderDetails") as GridView;
                string cs = ConfigurationManager.ConnectionStrings["SqlConnection"].ConnectionString;
                using (SqlConnection con = new SqlConnection(cs))
                {
                    DataTable orderDetailDT = new DataTable();
                    con.Open();
                    string orderDetail = "select ItemName,Quantity from Order_Details where Order_ID=" + order_ID + "";
                    SqlCommand cmd = new SqlCommand(orderDetail, con);
                    cmd.CommandType = CommandType.Text;
                    SqlDataAdapter orderDetailDA = new SqlDataAdapter(cmd);
                    orderDetailDA.Fill(orderDetailDT);
                    innerDataList.DataSource = orderDetailDT;
                    innerDataList.DataBind();

                }




            }
        }

NOTE: I also try to use string format in aspx file to achieve my desired time format but it didn't work

<asp:Label ID="lblOrderDate" runat="server" Text='<%#Eval("OrderDate","{0:t}") %>'.

Please guide me where the problem in the code why its only show data in odd no. Thankyou

Related posts

Recent Viewed