一:
<asp:GridView ID="gvPlatIncome" runat="server" AutoGenerateColumns="False"
EnableModelValidation="True" Width="96%" CssClass="tb1" ShowFooter="True">
<AlternatingRowStyle BorderWidth="1px" />
<Columns>
<asp:TemplateField HeaderText="男生ID">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("BoyID") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSub" runat="server" Text="小计"></asp:Label><br />
<asp:Label ID="lblSum" runat="server" Text="总计"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:BoundField DataField="GirlID" HeaderText="女生ID" />
<asp:BoundField DataField="StartTime" HeaderText="开始时间" />
<asp:BoundField DataField="EndTime" HeaderText="结束时间" />
<asp:TemplateField HeaderText="聊天时长(M)">
<ItemTemplate>
<asp:Label ID="lblChatMinutes" runat="server" Text='<%# Bind("ChatMinutes") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSubChatMinutes" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="lblSumChatMinutes" runat="server" Text="Label"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="平台收入($)">
<ItemTemplate>
<asp:Label ID="lblPlatIncome" runat="server"
Text='<%# Bind("PlatformIncomeDollor") %>'></asp:Label>
</ItemTemplate>
<FooterTemplate>
<asp:Label ID="lblSubToPlatIncome" runat="server" Text="Label"></asp:Label>
<br />
<asp:Label ID="lblSumToPlatIncome" runat="server" Text="Label"></asp:Label>
</FooterTemplate>
</asp:TemplateField>
</Columns>
<FooterStyle CssClass="trbg1" />
<SelectedRowStyle HorizontalAlign="Center"/>
</asp:GridView>
二:
if (list.Length != 0)
{
gvPlatIncome.Visible = true;
//当前页的平台收入小计
decimal currentIncomes = 0;
for (int i = 0; i < gvPlatIncome.Rows.Count; i++)
{
currentIncomes += Convert.ToDecimal((gvPlatIncome.Rows[i].FindControl("lblPlatIncome") as Label).Text);
}
//显示平台收入小计
(gvPlatIncome.FooterRow.FindControl("lblSubToPlatIncome") as Label).Text = currentIncomes.ToString();
//显示平台收入总计
(gvPlatIncome.FooterRow.FindControl("lblSumToPlatIncome") as Label).Text = totalIncoming.ToString();
三:
dvUserInfo.Fields[0].HeaderText = Resources.global.MemberID;
dvUserInfo.Fields[1].HeaderText = Resources.global.Email;
四:
dvUserInfo.Rows[11].Cells[1].Text = LanguageCache.GetState4Show(languageType, member.State);
五:
//动态改变标题
gridView.HeaderRow.Cells[0].Text = Resources.global.MemberID;
六:LinkButton事件下获取当前行
int row = ((GridViewRow)((LinkButton)sender).NamingContainer).RowIndex;
string userID = gvFreezeUser.Rows[row].Cells[0].Text.ToString();
GlobalUtil.BLService4Web.EnableMember(userID);
//解冻成功
Commons.ShowMessage(Page, Resources.global.unFreezeSuc);
this.ShowPage(0, false);
七:当使用BouldField绑定数据,这一列如果被隐藏的话,那么隐藏的值无法获得到.
在GridView中用BouldField绑定的内容时,通过下面得数据
GridView1.Rows[2].Cells[0].Text
在GridView中用BouldField绑定的内容时,当GridView处于编辑状态时,如何获得TextBox中用户输入的内容:
((TextBox)GridView1.Rows[2].Cells[0].Controls[0]).Text;
在GridView中,获得模板列中某个控件的值时,使用FindControl("")来得到这个控件
八: protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
this.Bind();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView1.EditIndex = -1;
this.Bind();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
int id = Convert.ToInt32(((Label)GridView1.Rows[e.RowIndex].Cells[8].FindControl("Label1")).Text);
roomTypeManager.Delete(id);
this.Bind();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
if (GridView1.EditIndex != -1)
{
int editRowIndex = GridView1.EditIndex;
string typeNameNew = ((TextBox)GridView1.Rows[editRowIndex].Cells[0].Controls[0]).Text;
// int id = Convert.ToInt32(GridView1.Rows[editRowIndex].Cells[9].Text);\
int id=Convert.ToInt32(((Label)GridView1.Rows[editRowIndex].Cells[8].FindControl("Label3")).Text);
RoomType updateRoomType = roomTypeManager.GetModel(id);
updateRoomType.TypeName = typeNameNew;
updateRoomType.AddBed = ((CheckBox)GridView1.Rows[editRowIndex].Cells[1].Controls[0]).Checked;
// updateRoomType.TypeId = id;
roomTypeManager.Update(updateRoomType);
GridView1.EditIndex = -1;
this.Bind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;//获取当前第几页
this.Bind();//数据进行重新绑定
}