我有一個GridView(AllItems)是這樣的:如何讓gridview顯示關聯數據源以外的數據?
的項目設備名稱,數量,一天的時間,備份時間和功率是從列表中提取: AllItems.DataSource =善堂;
項目TotalWatts,瓦時/紐約時報,瓦時/天必須由當地的整型變量中提取,但指定數據源不包含TotalWatts
什麼,我應該這樣做值,所給予的例外我的網格視圖也接受局部變量......?爲GridView控件
代碼:
<asp:GridView ID="AllItems" runat="server" AutoGenerateColumns="false" Height="124px" Width="191px" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="4" ForeColor="Black" GridLines="Horizontal" OnDataBound="AllItems_DataBound" ShowFooter="true" FooterStyle-BackColor="Black">
<Columns>
<asp:BoundField DataField="Applianc.Name" HeaderText="Appliance Name" />
<asp:BoundField DataField="Quantity" HeaderText="Quantity" />
<asp:BoundField DataField="DayTime" HeaderText="Day Time(Hrs)" />
<asp:BoundField DataField="BackUpTime" HeaderText="BackUp Time(Hrs)" />
<asp:BoundField DataField="Applianc.Power" HeaderText="Power(Watts)" />
<asp:BoundField DataField="TotalWatts" HeaderText="Total Watts" />
<asp:BoundField DataField="HrsNight" HeaderText="Wh/Nyt" />
<asp:BoundField DataField="HrsDay" HeaderText="Wh/Day" />
</Columns>
<FooterStyle BackColor="Black" ForeColor="White" Font-Italic="true" />
<FooterStyle BackColor="#CCCC99" ForeColor="Black" />
<HeaderStyle BackColor="#333333" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="Black" HorizontalAlign="Right" />
<SelectedRowStyle BackColor="#CC3333" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F7F7F7" />
<SortedAscendingHeaderStyle BackColor="#4B4B4B" />
<SortedDescendingCellStyle BackColor="#E5E5E5" />
<SortedDescendingHeaderStyle BackColor="#242121" />
</asp:GridView>
代碼頁背後按鈕點擊
protected void BtnAddNext_Click(object sender, EventArgs e)
{
List<Entity.UserSiteLoad> LstUsl = (List<Entity.UserSiteLoad>)Session["MyApplianceList"];
e_usl.Applianc = new Entity.Appliance();
calcObj = new CalculatorTest();
e_usl.IdUserSiteLoad = Guid.NewGuid().ToString();
e_usl.IdUserHousing = "xxx";
e_usl.IdAppliance = DDLAppName.SelectedItem.Value.ToString(); //<<------------
e_usl.Applianc.Name = DDLAppName.SelectedItem.Text;
e_usl.Applianc.Power = new Random().Next(20, 500);
e_usl.Quantity = Convert.ToInt32(QtyTB.Text);
e_usl.DayTime = Convert.ToInt32(DayTymTB.Text);
e_usl.BackUpTime = Convert.ToInt32(BackUpTymTB.Text);
e_usl.CreatedBy = "sana";
e_usl.CreatedDate = DateTime.Now;
//e_usl.CreationDate = DateTime.Now;
e_usl.ModifiedBy = "sana";
e_usl.ModifiedDate = DateTime.Now;
e_usl.IsActive = true;
e_usl.IsDeleted = false;
if (LstUsl.Count != 0)
{
for (int rowIndex = 0; rowIndex < LstUsl.Count; rowIndex++)
{
string AppName = LstUsl[rowIndex].Applianc.Name;
if (AppName == DDLAppName.SelectedItem.Text)
{
LstUsl.Remove(LstUsl[rowIndex]);
}
}
}
if (LstUsl.Count == 0 || LstUsl.Count > 0)
{
LstUsl.Add(e_usl);
}
Session["MyApplianceList"] = LstUsl;
currentIndex = LstUsl.Count - 1; //int variable
TotalWatts = calcObj.GetTotalWattsOfEachAppliance(currentIndex); //int variable
HrsNight = calcObj.GetWattsHrPerNight(currentIndex); //int variable
HrsDay = calcObj.GetWattsHrPerDayForEachAppliance(currentIndex); //int variable
Response.Write("List Count is: " + LstUsl.Count); //check
AllItems.DataSource = LstUsl;
AllItems.DataBind();
AllItems.Visible = true;
Session["MyApplianceList"] = LstUsl;
}
你需要向我們展示你如何寫網格視圖 – AMember
是啊..編輯。已經放置了代碼 –