20151224001 GridView 多按钮的各种使用方法
<asp:GridView ID="GridView1"
runat="server" AllowPaging="True" AutoGenerateColumns="False"
BackColor="#78C7EB" BorderColor="#78C7EB" BorderWidth="1px"
CellPadding="3" CellSpacing="2" DataKeyNames="ID"
Height="50px" Width="810px" style="left: 3px; top: 3px"
OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowDataBound="GridView1_RowDataBound"
Font-Size="Large" PageSize="5"
onselectedindexchanged="GridView1_SelectedIndexChanged"
onrowcommand="GridView1_RowCommand" onrowdeleting="GridView1_RowDeleting">
<FooterStyle BackColor="#F7DFB5" ForeColor="#46434F" Font-Bold="False" />
<RowStyle BackColor="#EDF6FA" ForeColor="#46434F" />
<Columns>
<asp:CommandField HeaderText="查看" ShowSelectButton="True" SelectText="查看" >
<HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#003300" />
</asp:CommandField>
<asp:CommandField DeleteText="变更" HeaderText="变更" ShowDeleteButton="True">
<HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#CA0ED3" />
</asp:CommandField>
<asp:ButtonField ButtonType="Button" Text="取消" HeaderText="取消"
CommandName="b_cancel">
<ControlStyle ForeColor="#800010" />
<HeaderStyle BackColor="#4B9D1A" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="38px" ForeColor="#CA0ED3" />
</asp:ButtonField>
<asp:BoundField DataField="ID" HeaderText="编号" ReadOnly="True"
SortExpression="ID" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="28px" />
</asp:BoundField>
<asp:BoundField DataField="M_Title" HeaderText="会议主题" SortExpression="M_Title" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="160px" />
</asp:BoundField>
<asp:BoundField DataField="M_Room" HeaderText="会议室" SortExpression="M_Room" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="M_Chairman" HeaderText="主持人"
SortExpression="M_Chairman" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="M_S_Time" HeaderText="开始时间"
SortExpression="M_S_Time" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="M_E_Time" HeaderText="结束时间"
SortExpression="M_E_Time" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
</asp:BoundField>
<asp:BoundField DataField="M_Person" HeaderText="与会人"
SortExpression="M_Person" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="100px" />
</asp:BoundField>
<asp:BoundField DataField="M_Operator" HeaderText="预约人"
SortExpression="M_Operator" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="60px" />
</asp:BoundField>
<asp:BoundField DataField="M_Operator_Date" HeaderText="预约时间"
SortExpression="M_Operator_Date" >
<HeaderStyle BackColor="#34A7DC" BorderColor="#336699" BorderStyle="Double"
BorderWidth="1px" Font-Size="Medium" />
<ItemStyle HorizontalAlign="Center" BorderWidth="1px"
Font-Size="Small" BorderColor="#34A7DC" Width="80px" />
</asp:BoundField>
</Columns>
<PagerStyle ForeColor="#EDF6FA" HorizontalAlign="Center" Font-Bold="True"
Font-Italic="False" Font-Names="Arial Black" Font-Overline="False"
Font-Size="Medium" Font-Underline="False" Height="28px" />
<SelectedRowStyle BackColor="#4B9D1A" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#EDF6FA" Font-Bold="True" ForeColor="White"
Font-Size="Small" Height="38px" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
******************************************************************************************************
protected void databind()
{
P_ht.H_data P_data = new P_ht.H_data();
P_data.sql_text1 = Str_sql;
P_data.select_tables();
DataSet1 = P_data.DataSet8;
Session["session_table"] = P_data.DataSet8;
this.GridView1.DataSource = DataSet1;
this.GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
this.DataSet2 = new System.Data.DataSet();
this.DataSet2 = (DataSet)Session["session_table"];
this.GridView1.DataSource = this.DataSet2;
this.GridView1.DataBind();
}
//
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = -1; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#bcbf56'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
if (e.Row.RowType == DataControlRowType.DataRow)
{
//Button b = e.Row.Cells[0].Controls[0] as Button;
Button b = e.Row.Cells[2].Controls[0] as Button;
b.Attributes.Add("onclick", "if(confirm('你确认要取消选中的会议预约吗?')){ __doPostBack('GridView1','$" + e.Row.RowIndex + "')}else{return false;}");
}
}
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
//GridView g = (e.CommandSource as GridView);
////Label1.Text = "你选择的行 ID = " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value;
//if (Convert.ToInt32(g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value) != null)
//{
// if (Convert.ToInt32(g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString()) > 0)
// {
// ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
// scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString() + " ');", true);
// }
//}
// 在RowCommand事件中通过CommandName来区分点击了哪个Button
GridView g = (e.CommandSource as GridView);
if (e.CommandName == "b_cancel")
{
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: " + g.DataKeys[Convert.ToInt32(e.CommandArgument)].Value.ToString() + " ');", true);
}
}
//
static string str_ca = "";
protected void btn_i_date1_Click(object sender, ImageClickEventArgs e)
{
LayerCC.Visible = !LayerCC.Visible;
str_ca = "1";
}
protected void btn_i_date2_Click(object sender, ImageClickEventArgs e)
{
LayerCC.Visible = !LayerCC.Visible;
str_ca = "2";
}
protected void Calendar1_SelectionChanged(object sender, EventArgs e)
{
if (str_ca == "1")
{
txt_date1.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
LayerCC.Visible = false;
}
if (str_ca == "2")
{
txt_date2.Text = Calendar1.SelectedDate.ToString("yyyy-MM-dd");
LayerCC.Visible = false;
}
}
protected void btn_i_confirm_Click(object sender, ImageClickEventArgs e)
{
//
string str_room = "";
if (Session["meeting_room"] == null)
{
str_room = "";
}
else
{
str_room = Session["meeting_room"].ToString();
}
//
dt1 = System.Convert.ToDateTime(txt_date1.Text.Trim() + " 00:00:00 ");
dt2 = System.Convert.ToDateTime(txt_date2.Text.Trim() + " 23:59:59 ");
//
databind();
}
//
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
GridViewRow row = GridView1.SelectedRow;
// Display the company name from the selected row.
// In this example, the third column (index 2) contains
// the company name.
//Message.Text = "You selected " + row.Cells[2].Text + ". ";
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: " + row.Cells[3].Text + " 查看 ');", true);
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
//string str_a = e.RowIndex.ToString();
//string str_a = e.Keys.ToString();
ClientScriptManager scriptManager = ((Page)System.Web.HttpContext.Current.Handler).ClientScript;
scriptManager.RegisterStartupScript(typeof(string), "", "alert('提示: " + GridView1.Rows[e.RowIndex].Cells[3].Text.ToString().Trim() + " 编辑 ');", true);
}
}
20151224001 GridView 多按钮的各种使用方法的更多相关文章
- gridview获取当前行索引的方法
在用GridView控件时,我们经常会碰到获取当前行的索引,通过索引进行许多操作.例如,可以获得当前行某一个控件元素:设置某一元素的值等等. 下面结合实例介绍几种获得GridView当前行索引值的方法 ...
- Android中用GridView实现九宫格的两种方法(转)
Android中用GridView实现九宫格的两种方法http://blog.csdn.net/shakespeare001/article/details/7768455 1.传统办法:实现一个继承 ...
- android 之 ListView 里面嵌套 GridView 遇到的问题及其解决方法。
我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. g ...
- 关于gridview里加按钮事件的总结
1. onrowcommand="GridView1_RowCommand1" 在gridview申明时的属性里要有,然后找到闪电,双击 还有要把那个按钮行模板化,就是箭头里面的t ...
- ListView 里面嵌套 GridView 遇到的问题及其解决方法。
我们直接入主题.所有问题例子请参照下图 1,怎样使图片具有点击事件? 答: 解决方法: 在你的BaseAdapter里面不要设置下面这三个东西,然后再设置GridView的onItemClick. g ...
- Android 防止按钮连续点击的方法(Button,ImageButton等)
防止按钮连续点击 其实实现很简单 共通方法 public class Utils { private static long lastClickTime; public static boolean ...
- BootStrap中按钮点击后被禁用按钮的最佳实现方法
//禁用button $('button').addClass('disabled'); // Disables visually $('button').prop('disabled', true) ...
- dev gridview表格按钮
固定列的位置 添加按钮控件位置,使用buttonEdit 添加按钮 按钮属性设置 按钮设置后的效果 //注册按钮事件 this.ribtndata.ButtonClick += new DevExpr ...
- (转)解决ScrollView嵌套ListView或者GridView导致只显示一行的方法
即动态获取ListView和GridView的高度 一.对于ListView ListView listview= new ListView(this); setListViewHeightBased ...
随机推荐
- 关于Eclipse的unsupported major minor version 51.0 错误
把别人的工程 拿来运行报上述错误 是因为工程版本不对 解决办法:新建工程 把现有的代码或资源文件 拷到新建工程里
- eclipse JAVA实现AES的加密和解密算法
import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.Secre ...
- Singlton设计模式
单例定义: 确保一个类只有一个实例,并提供全局访问点. 适用场景: 1.) 当系统中某个类必须仅有一个实例对象,同时访问该系统的所有访问者必须访问同一个实例对象时,且该对象实例自身占用资源又不大时. ...
- 系统性能调优CPU与内存
CPU相关术语 处理器:插到系统插槽或者处理器版上的物理芯片,以核或者硬件线程的方式包含了一块或者多块CPU. 核:一颗多核处理器上的一个独立CPU实例.核的使用时处理器扩展的一种方式,有称为芯片级多 ...
- ads 的一些错误
遇到动不动就有*.o文件找不到的情况,而且通常都是开始的时候可以正常LINK,而经过若干次重新LINK后却找不到(即使只是在代码中加一个无关紧要得空格),新建个工程,将目前的.C和.H文件原封不动加进 ...
- G面经prepare: Jump Game Return to Original Place
第二题 算法 给你一个arr 返回 T 或者 F arr的每个数代表从这个点开始跳几部,返回T的情况:从这个arr中任意一个数开始跳,可以在每个元素都跳到且只跳到一次的情况下返回到开始跳的元素 比如[ ...
- C++之路进阶——bzoj1030(文本生成器)
F.A.Qs Home Discuss ProblemSet Status Ranklist Contest ModifyUser hyxzc Logout 捐赠本站 Notice:由于本OJ建立在 ...
- bzoj4238 电压
首先先直接对图进行二染色,dfs染完色后,有的边为搜索树边,有的为非树边,当非树边连接的两头的点为异色的时候,那么很明显这条非树边和树边构成的环上的边必然不可能成为答案:如果非树边的两端的点同色,那么 ...
- mongodb聚合内存不足解决方案
原因:mongodb每一个文档默认只有16M.聚合的结果是一个BSON文档,当超过16M大小时,就会报内存不够错误. exceeded memory limit for $group.but didn ...
- 轻量linux-Crunch bang
主页地址:http://crunchbang.org crunch bang11昵称 wheezy crunchbang 11 基于 debian7