前台:.aspx
<asp:GridView ID="gvBankData" runat="server" AutoGenerateColumns="False" Width="1095px"
AllowPaging="True" OnPageIndexChanging="gvBankData_PageIndexChanging" OnRowUpdating="gvBankData_RowUpdating"
OnRowCancelingEdit="gvBankData_RowCancelingEdit" OnRowEditing="gvBankData_RowEditing"
PageSize="30" EmptyDataText="暂无可上传崔记数据">
<HeaderStyle BackColor="#c5d6e6" HorizontalAlign="center" ForeColor="#10205c" />
<RowStyle Height="22px" HorizontalAlign="Center" />
<Columns>
<asp:TemplateField HeaderText="选择">
<HeaderTemplate>
<asp:CheckBox runat="server" ID="cbHead" OnCheckedChanged="SelectAll" AutoPostBack="true"
Text="全选" Width="50px"></asp:CheckBox>
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox runat="server" ID="cbItem"></asp:CheckBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lbl_ID" Text='<%# Eval("recordid") %>' runat="server" Width="70px"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_ID" runat="server" Text='<%# Eval("recordid") %>' Width="70px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="50px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="recordid" HeaderText="ID" >
</asp:BoundField>--%>
<asp:TemplateField HeaderText="案件编号">
<ItemTemplate>
<asp:Label ID="lbl_AJBH" Text='<%# Eval("caseid") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_AJBH" runat="server" Text='<%# Eval("caseid") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="135px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="caseid" HeaderText="案件编号" />--%>
<asp:TemplateField HeaderText="催收渠道">
<ItemTemplate>
<asp:Label ID="lbl_CSQD" Text='<%# Eval("催收渠道") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_CSQD" runat="server" Text='<%# Eval("催收渠道") %>' Width="50px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="65px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="催收渠道" HeaderText="催收渠道"></asp:BoundField>--%>
<asp:TemplateField HeaderText="P_code">
<ItemTemplate>
<asp:Label ID="lbl_P_code" Text='<%# Eval("P_code") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_P_code" runat="server" Text='<%# Eval("P_code") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="P_code" HeaderText="P_code"></asp:BoundField>--%>
<asp:TemplateField HeaderText="催收结果">
<ItemTemplate>
<asp:Label ID="lbl_CSJG" Text='<%# Eval("催收结果") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_CSJG" runat="server" Text='<%# Eval("催收结果") %>' Width="50px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="65px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="催收结果" HeaderText="催收结果"></asp:BoundField>--%>
<asp:TemplateField HeaderText="C_code">
<ItemTemplate>
<asp:Label ID="lbl_C_code" Text='<%# Eval("C_code") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_C_code" runat="server" Text='<%# Eval("C_code") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="100px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="C_code" HeaderText="C_code"></asp:BoundField>--%>
<asp:TemplateField HeaderText="证件号码">
<ItemTemplate>
<asp:Label ID="lbl_ZJHM" Text='<%# Eval("证件号码") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_ZJHM" runat="server" Text='<%# Eval("证件号码") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="150px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="证件号码" HeaderText="证件号码" />--%>
<asp:TemplateField HeaderText="催收时间">
<ItemTemplate>
<asp:Label ID="lbl_CSSJ" Text='<%# Eval("催收时间") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_CSSJ" runat="server" Text='<%# Eval("催收时间") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="155px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="催收时间" HeaderText="催收时间" />--%>
<asp:TemplateField HeaderText="催收方式">
<ItemTemplate>
<asp:Label ID="lbl_CSFS" Text='<%# Eval("催收方式") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_CSFS" runat="server" Text='<%# Eval("催收方式") %>' Width="50px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="65px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="催收方式" HeaderText="催收方式" />--%>
<asp:TemplateField HeaderText="拨打电话">
<ItemTemplate>
<asp:Label ID="lbl_BDDH" Text='<%# Eval("拨打电话") %>' runat="server"></asp:Label>
</ItemTemplate>
<%--<EditItemTemplate>
<asp:TextBox ID="txt_BDDH" runat="server" Text='<%# Eval("拨打电话") %>' Width="100px"
Font-Size="10px"></asp:TextBox>
</EditItemTemplate>--%>
<HeaderStyle Width="150px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="拨打电话" HeaderText="拨打电话" />--%>
<asp:TemplateField HeaderText="联系结果">
<ItemTemplate>
<asp:Label ID="lbl_LXJG" Text='<%# Eval("联系结果") %>' runat="server"></asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="txt_LXJG" runat="server" Text='<%# Eval("联系结果") %>' Width="170px"
Font-Size="12px"></asp:TextBox>
</EditItemTemplate>
<HeaderStyle Width="160px" />
</asp:TemplateField>
<%--<asp:BoundField DataField="联系结果" HeaderText="联系结果" />--%>
<asp:TemplateField HeaderText="操作">
<ItemTemplate>
<asp:ImageButton ID="btn_Edit" runat="server" ImageUrl="~/Images/icon_edit.gif" CommandName="Edit" />
</ItemTemplate>
<EditItemTemplate>
<asp:LinkButton ID="Button1" runat="server" Text="更新" CommandName="Update" />
<asp:LinkButton ID="Button3" runat="server" Text="取消" CommandName="Cancel" />
</EditItemTemplate>
<HeaderStyle Width="60px" />
</asp:TemplateField>
</Columns>
<PagerTemplate>
当前第:
<%--//((GridView)Container.NamingContainer)就是为了得到当前的控件--%>
<asp:Label ID="LabelCurrentPage" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
页/共:
<%--//得到分页页面的总数--%>
<asp:Label ID="LabelPageCount" runat="server" Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
页
<%--//如果该分页是首分页,那么该连接就不会显示了.同时对应了自带识别的命令参数CommandArgument--%>
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible='<%#((GridView)Container.NamingContainer).PageIndex != 0 %>' BackColor="#0099FF">[首页]</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev"
CommandName="Page" Visible='<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>'
BackColor="#0099FF">[上一页]</asp:LinkButton>
<%--//如果该分页是尾页,那么该连接就不会显示了--%>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'
BackColor="#0099FF">[下一页]</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible='<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>'
BackColor="#0099FF">[尾页]</asp:LinkButton>
转到第
<asp:TextBox ID="txtNewPageIndex" runat="server" Width="20px" Text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />页
<%--//这里将CommandArgument即使点击该按钮e.newIndex 值为3 --%>
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-2"
CommandName="Page" Text="GO" />
</PagerTemplate>
</asp:GridView>
后台:.aspx.cs
/// <summary>
/// 点击分页下面的(首页/上一页/下一页/尾页/Go)
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvBankData_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 得到该控件
GridView theGrid = sender as GridView;
int newPageIndex = 0;
if (e.NewPageIndex == -3)
{
//点击了Go按钮
TextBox txtNewPageIndex = null;
//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//得到text控件
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}
if (txtNewPageIndex != null)
{
//得到索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
//点击了其他的按钮
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
//得到新的值
theGrid.PageIndex = newPageIndex;
//重新绑定
gv_Load(txtStartTime.Text, txtEndTime.Text);
Load_Text();
}
/// <summary>
/// 复选框全选
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void SelectAll(object sender, EventArgs e)
{
bool isChecked = ((CheckBox)(gvBankData.HeaderRow.Cells[0].FindControl("cbHead"))).Checked;
foreach (GridViewRow gvRow in gvBankData.Rows)
{
((CheckBox)(gvRow.Cells[0].FindControl("cbItem"))).Checked = isChecked;
}
}
/// <summary>
/// 更新按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvBankData_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
try
{
string ID = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_ID")).Text;//recordid
string AJBH = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_AJBH")).Text;//案件编号caseid
string CSQD = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_CSQD")).Text;//催收渠道
string P_code = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_P_code")).Text;//P_code
string CSJG = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_CSJG")).Text;//催收结果
string C_code = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_C_code")).Text;//C_code
string ZJHM = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_ZJHM")).Text;//证件号码
string CSSJ = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_CSSJ")).Text;//催收时间
string CSFS = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_CSFS")).Text;//催收方式
string BDDH = ((Label)gvBankData.Rows[e.RowIndex].FindControl("lbl_BDDH")).Text;//拨打电话
string LXJG = ((TextBox)gvBankData.Rows[e.RowIndex].FindControl("txt_LXJG")).Text;//联系结果
sql = string.Format(@" update Memo set Memo='{0}' where RecordID='{1}' ", LXJG, ID);
//执行sql语句
Paging.OpenSql(sql);
gvBankData.EditIndex = -1;
gv_Load(txtStartTime.Text, txtEndTime.Text);
Load_Text();
}
catch (Exception ex)
{
Response.Write("<script language='javascript'>window.alert('" + ex.Message + "!');</script>");
//将错误信息记录到日志文件
Log.Error(ex.Message);
}
}
/// <summary>
/// 编辑按钮
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvBankData_RowEditing(object sender, GridViewEditEventArgs e)
{
gvBankData.EditIndex = e.NewEditIndex;
gv_Load(txtStartTime.Text, txtEndTime.Text);
//Load_Text();
}
/// <summary>
/// 自适应列宽
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvBankData_RowDataBound(object sender, GridViewRowEventArgs e)
{
Auto_Column_width(e);
}
/// <summary>
/// 取消
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void gvBankData_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
gvBankData.EditIndex = -1;
gv_Load(txtStartTime.Text, txtEndTime.Text);
Load_Text();
}
/// <summary>
/// 自适应列宽
/// </summary>
/// <param name="e"></param>
private static void Auto_Column_width(GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Header)
{
for (int i = 0; i < e.Row.Cells.Count; i++)
{
e.Row.Cells[i].Text = "<nobr> " + e.Row.Cells[i].Text + " </nobr>";
}
}
}
/// <summary>
/// 分页数量下拉框文本值改变时触发的事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
protected void drp_NumInfo_SelectedIndexChanged(object sender, System.EventArgs e)
{
gvBankData.PageSize = Convert.ToInt32(drp_NumInfo.Text);
gv_Load(txtStartTime.Text, txtEndTime.Text);
Load_Text();
}