我有一个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
是啊..编辑。已经放置了代码 –