我的页面中有两个数据列表,其中一个嵌套在另一个中。我想在页面加载事件期间在运行时提供他们的数据源,但是我的内部数据列表没有显示数据表的值,我不知道如何将我的内部数据列表数据源设置为数据表运行。
我已经搜索了很多关于它的信息,但我找不到有用的信息。请帮我。
在页面中,我想显示哪个用户购买了哪些产品,显示每个产品的数量和价格,并显示一些有关付费索引的信息。如索引号或索引库名称。问题是,对于一个索引号,我可以拥有多个产品。为了向每个索引号显示相关产品,我使用了嵌套数据列表。现在,在我的第一个数据列表中,我的外部(父)数据列表可以显示信息,但应该显示产品信息的内部数据列表不显示任何内容。
我真的需要帮助
这是我的代码:
<asp:DataList ID="outerDataLiat" runat="server" RepeatColumns="1"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" ForeColor="Black" GridLines="Both" DataKeyField="idfromIndex" OnItemDataBound="DataList1_ItemDataBound" />
<FooterStyle BackColor="#CCCCCC" />;
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="White" />
<ItemTemplate />
<fieldset>
<legend>>customer information<</legend>>
<table style="width: 100%;"/>
<tr>
<td>
customer code:
</td>
<td>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("idFromUsers") %>'</asp:Label>
</td>;
<td>
telephone:
</td>
<td>
<asp:Label ID="Label2" runat="server" Text='<%# Eval("user_phone") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
customer name :
</td>
<td>
<asp:Label ID="Label3" runat="server" Text='<%# Eval("user_name") %>'></asp:Label>
</td>
<td>
cellphone number:
</td>
<td>
<asp:Label ID="Label4" runat="server" Text='<%# Eval("user_cellphone") %>'></asp:Label>
</td>
</tr>
<tr>
<td>
customer familly name :
</td>
<td>
<asp:Label ID="Label5" runat="server" Text='<%# Eval("user_familly") %>'></asp:Label>
</td>
<td>
email :
</td>
<td>
<asp:Label ID="Label6" runat="server" Text='<%# Eval("user_email") %>'></asp:Label>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>Index Information</legend>
<table style="width: 100%;">
<asp:Label ID="hiddenLable" runat="server" Text='<%# Eval("idfromIndex") %>' Visible="false"></asp:Label>
<tr>
<td>
Index number :
</td>
<td>
<asp:Label ID="Label7" runat="server" Text='<%# Eval("IndexNO") %>'></asp:Label>
</td>
<td>
date of index :
</td>
<td>
<asp:Label ID="Label8" runat="server" ></asp:Label>
</td>
<td>
bank name:
</td>
<td>
<asp:Label ID="Label9" runat="server" Text='<%# Eval("bankName") %>'></asp:Label>
</td>
</tr>
</table>
</fieldset>
<fieldset>
<legend>purchased products</legend>
<asp:DataList ID="innerDataLiat" runat="server" RepeatColumns="1"
BackColor="#CCCCCC" BorderColor="#999999" BorderStyle="Solid" BorderWidth="3px"
CellPadding="4" CellSpacing="2" ForeColor="Black" GridLines="Both" OnItemDataBound="DataList2_ItemDataBound" >
<FooterStyle BackColor="#CCCCCC" />
<HeaderStyle BackColor="Black" Font-Bold="True" ForeColor="White" />
<ItemStyle BackColor="White" />
<ItemTemplate >
<table style="width: 100%;" id="tbl1"></table>
<table style="width: 100%;">
<tr>
<td>
product name :
</td>
<td>
<asp:Label ID="Label10" runat="server" Text=""></asp:Label>
</td>
<td>
quantity:
</td>
<td>
<asp:Label ID="Label11" runat="server" Text=""></asp:Label>
</td>
<td>
unit price of each product :
</td>
<td>
<asp:Label ID="Label12" runat="server" Text=""></asp:Label>
</td>
<td>
Total Amount:
</td>
<td>
<asp:Label ID="Label13" runat="server" Text=""></asp:Label>
</td>
</tr>
</table>
</ItemTemplate>
</asp:DataList>
</fieldset>
<fieldset><legend>shopping cart Information</legend>
<table style="width: 100%;">
<tr>
<td >
Total quantity :
</td>
<td>
<asp:Label ID="Label14" runat="server" Text=""></asp:Label>
</td>
<td>
total amount of shopping cart:
</td>
<td>
<asp:Label ID="Label15" runat="server" Text=""></asp:Label>
</td>
</tr>
<tr>
<td> date of shopping :</td>
<td dir="rtl"> <asp:Label ID="Label16" runat="server" Text='<%# Eval("orderDate") %>' /></td>
</tr>
</table>
</fieldset>
<asp:LinkButton ID="LinkButton1" runat="server" CommandName="confirm">confirm</asp:LinkButton>
<asp:LinkButton ID="LinkButton2" runat="server" CommandName="notconfirm">not confirm</asp:LinkButton>
</ItemTemplate>
<SelectedItemStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />
</asp:DataList>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getDistinctOrderId();
doPaging();
}
}
private void getDistinctOrderId()
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["mobile_storeConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT min(id), [idfromIndex] FROM Orders WHERE [idfromIndex] IN(SELECT DISTINCT [idfromIndex] FROM Orders) GROUP BY [idfromIndex] ";
DataView MyDv = new DataView();
try
{
myConnection.Open();
SqlDataReader dr = cmd.ExecuteReader();
DataTable dt = new DataTable();
dt.Load(dr);
MyDv = dt.DefaultView;
for (int i = 0; i < MyDv.Count; i++)
{
if (i == MyDv.Count - 1)
{
distinctList += MyDv[i][0].ToString();
}
else
distinctList += MyDv[i][0].ToString() + ",";
}
}
catch (Exception EXP)
{
}
finally
{ myConnection.Close(); }
}
public DataTable getTheData()
{
DataSet DS = new DataSet();
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString1"].ConnectionString);
SqlDataAdapter objSQLAdapter = new SqlDataAdapter("select idfromIndex,user_name,user_email,indexNO,bankName,Ispay,user_familly,user_cellphone,orderDate,user_phone,idFromUsers,orderId from factors where orderId IN (" + distinctList + ")", myConnection); objSQLAdapter.Fill(DS, "mobile_store");
return DS.Tables[0];
}
void doPaging()
{
//DataTable mydatatable =
pagedData.DataSource = getTheData().DefaultView;
pagedData.AllowPaging = true;
pagedData.PageSize = 4;
/*
...
here I wrote some code to make my outer datalist pagable
...
*/
outerDataLiat.DataSource = pagedData;
outerDataLiat.DataBind();
}
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
{
if ((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == ListItemType.AlternatingItem))
{
Label lbl = (Label)e.Item.FindControl("hiddenLable");
string idfromindex = lbl.Text;
DataList lst2 = (DataList)e.Item.FindControl("innerDataLiat");
SqlDataSource ds = new SqlDataSource();
DataTable mydt = new DataTable();
dataset t = setinnerDataList(idfromindex);
tb2 = t;
int sumqty = 0;
double sumprice = 0;
for (int i = 0; i < t.Rows.Count; i++)
{
sumprice += Convert.ToDouble(t.Rows[i]["p_price"]) * Convert.ToInt32(t.Rows[i]["qty"]);
sumqty += Convert.ToInt32(t.Rows[i]["qty"]);
}
Label lbl14 = (Label)e.Item.FindControl("Label14");
lbl14.Text = sumqty.ToString();
Label lbl15 = (Label)e.Item.FindControl("Label15");
lbl15.Text = sumprice.ToString();
Label pname = (Label)lst2.FindControl("pname");
Label qty = (Label)lst2.FindControl("qty");
Label price = (Label)lst2.FindControl("unit_price");
DataRow[] dr = t.Tables[0].Select("idfromIndex = '" + idfromindex + "'");//new DataRow[t.Tables[0].Rows.Count]; //= //This will select all rows where the Name Column has value MAK
for (int i = 0; i < t.Tables[0].Rows.Count; i++)
{
dr[i] = t.Tables[0].Rows[i];
}
for (int i = 0; i < dr.Length; i++)
{
pname.Text = dr[i]["pname"].ToString();
price.Text = dr[i]["p_price"].ToString();
qty.Text = dr[i]["qty"].ToString();
}
}
}
private dataset setinnerDataList(string idfromindex)
{
SqlConnection myConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["mobile_storeConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand();
cmd.Connection = myConnection;
cmd.CommandType = CommandType.Text;
cmd.CommandText = "SELECT [pname], [p_price], [idfromIndex], [qty] FROM [factors] WHERE ([idfromIndex] = " + idfromindex + ") ";
DataView MyDv = new DataView();
dataset dt = new DataTable();
try
{
myConnection.Open();
SqlDataReader dr = cmd.ExecuteReader();
dt.Load(dr);
dr.Close();
}
catch (Exception EXP)
{
}
finally
{ myConnection.Close(); }
return dt;
}</pre>