horizontalalign(horizontalalignment matlab)

http://www.itjxue.com  2023-01-28 01:51  来源:未知  点击次数: 

asp.net中在Gridview中自定义一列操作,应该怎么做?

思路:先定义事件,在linkbutton上绑定事件,也就是一个CRUD的方法,然后在后台的OnRowCommand事件里调用绑定的事件即可。

具体举例如下:

1、前端的代码如下:

asp:GridView ID="gridViewDxjk" CssClass="gridview" runat="server" AllowPaging="True"

DataKeyNames="P_ID" AutoGenerateColumns="False"

RowStyle-HorizontalAlign="Center" BorderWidth="1px" PageSize="17"

onrowdeleting="gridViewDxjk_RowDeleting"

OnRowDataBound="gridViewDxjk_RowDataBound"

onpageindexchanging="gridViewDxjk_PageIndexChanging"

HeaderStyle CssClass="head" /

PagerStyle CssClass="pager" /

RowStyle CssClass="row" /

EditRowStyle CssClass="editrow" /

AlternatingRowStyle CssClass="altrow" /

EmptyDataRowStyle CssClass="empty" /

Columns

asp:HyperLinkField HeaderText="编辑" ControlStyle-Width="50" DataNavigateUrlFields="P_ID" DataNavigateUrlFormatString="smsModify.aspx?id={0}" Text="编辑"

ControlStyle Width="50px"/ControlStyle/asp:HyperLinkField

asp:CommandField ShowDeleteButton="true" DeleteText="删除"

ControlStyle Width="50px"/ControlStyle/asp:CommandField

asp:BoundField DataField="P_ID" HeaderText="id" SortExpression="P_ID" ItemStyle-HorizontalAlign="Center" Visible="False"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_NAME" HeaderText="名称" SortExpression="P_NAME" /

asp:BoundField DataField="P_Type" HeaderText="通知方式" SortExpression="P_Type" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_Fzr" HeaderText="姓名" SortExpression="P_Fzr" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_tel" HeaderText="通知手机" SortExpression="P_tel" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_jg" HeaderText="通知间隔(小时)" SortExpression="P_jg" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_on" HeaderText="是否开启" SortExpression="P_on" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_lasttime" HeaderText="最后发送时间" SortExpression="P_lasttime" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

asp:BoundField DataField="P_memo" HeaderText="备注" SortExpression="P_memo" ItemStyle-HorizontalAlign="Center"

ItemStyle HorizontalAlign="Center"/ItemStyle/asp:BoundField

/Columns

EmptyDataTemplate

没有数据!

/EmptyDataTemplate

PagerTemplate

table width="100%" class="gvPage" style="font-size:12px;"

tr

td style="text-align: right"

第asp:Label ID="lblPageIndex" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageIndex + 1 %'/asp:Label页

/共asp:Label ID="lblPageCount" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageCount %'/asp:Label页

asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page" Visible="%# ((GridView)Container.NamingContainer).PageIndex != 0 %"首页/asp:LinkButton

asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page" Visible="%# ((GridView)Container.NamingContainer).PageIndex != 0 %"上一页/asp:LinkButton

asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page" Visible="%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %"下一页/asp:LinkButton

asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page" Visible="%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %"尾页/asp:LinkButton

asp:TextBox ID="txtNewPageIndex" runat="server" Text='%# ((GridView)Container.Parent.Parent).PageIndex + 1 %' Width="20px" AutoPostBack="true" /asp:TextBox

asp:LinkButton ID="btnGoEx" runat="server" CommandArgument="GO" CommandName="Page" Text="GO" OnClick="btnGoEx_Click"/asp:LinkButton

/td

/tr

/table

/PagerTemplate

/asp:GridView

2、后端的话,由于需要弹出删除前的确认框,所以,这里需要在RowDataBound里面做点逻辑,同时,要想真正的删除,还需要触发RowDeleting事件,具体代码如下:

//报警删除

protected void gridViewDxjk_RowDeleting(object sender, GridViewDeleteEventArgs e)

{

string key = gridViewDxjk.DataKeys[e.RowIndex].Value.ToString();

bool flag = bll.Delete(Int32.Parse(key));

if (flag)

NXT_WLService.App_Code.JScript.Alert("删除成功!", this);

else

NXT_WLService.App_Code.JScript.Alert("删除失败!", this);

}

protected void gridViewDxjk_RowDataBound(object sender, GridViewRowEventArgs e)

{

if (e.Row.RowType == DataControlRowType.DataRow)

{

LinkButton btn = (LinkButton)e.Row.Cells[1].Controls[0];

if (btn.Text.Equals("删除"))//删除钮才加提示讯息

btn.OnClientClick = "if (confirm('你确认要删除?')) javascript:__doPostBack('gridViewDxjk','Delete$" + e.Row.RowIndex.ToString() + "'); else return false;";

}

}

gridview 中的控件位置调整

我说一下呀 上边的太复杂了呀 挺简单的事情

通常你可以自己添加一个列 点击数据绑定那个箭头

之后选择添加列 添加一个Templeate列也就是模板列

之后选择修改列 你可以看到你添加的列在最下边

下边的问题是最关键的你在你添加列的右边可以看到一个上移还有下移还有删除的箭头 这个是用来调整列的位置的 把你想添加的LINKBUTTON列的位置 可以通过它来调整 任何列都可以调整位置的

完全系统自动修改的不需要你手动添加代码的

DataTable绑定到datagrid后,怎么在程序中设置各列的居中属性

DataTable绑定到datagrid后,在程序中设置各列的居中属性方法:

使用下面的语句可以定义列标题的对齐方式

Datagrid1.Columns(0).Alignment = 2

Datagrid1.Refresh

其中将Aligment设置为0为左对齐、1为右对齐、2为居中对齐

也可以用数据内容居中

private void DataGrid_ItemDataBound(object sender, DataGridItemEventArgs e)

{

for (int i=0; i e.Item.Cells.Count; i++)

e.Item.Cells[i].HorizontalAlign=HorizontalAlign.Center;

}

GridView控件启用编辑时怎么样使某些列不可被编辑?

当系统标识为用户自定义的时候修改删除可编辑,否则不可编辑!由于设置权限问题,所有在gridview控件中有一个系统标识的掩藏列:

Columns

asp:TemplateField

ItemTemplate

input type="checkbox" id="ckvalue" %#Eval("Function_IsSys").ToString() == "2"? " " :"disabled='disabled'" % name="ckvalue" value='%# Eval("Function_ID") %' //ItemTemplate

HeaderTemplate

input type="checkbox" id="ckall" name="ckall" disabled="disabled" onclick="CheckAll(this.checked,'ckvalue')" //HeaderTemplate

ItemStyle HorizontalAlign="Center" Width="5%" /

HeaderStyle HorizontalAlign="Center" /

/asp:TemplateField

asp:BoundField HeaderStyle-CssClass="display" ItemStyle-CssClass="display" DataField="Function_IsSys" /

asp:TemplateField HeaderText="功能编码"

ItemTemplate

%--a href="javascript:location.href='UserInfoView.aspx?id=%# Eval("Function_NO") %'" title="详细"--%%# Eval("Function_NO")%/a

/ItemTemplate

HeaderStyle Font-Bold="False" HorizontalAlign="Center" /

ItemStyle HorizontalAlign="Center" /

/asp:TemplateField

asp:BoundField HeaderText="功能名称" DataField="Function_Name"

HeaderStyle HorizontalAlign="Center" Font-Bold="False" /

ItemStyle HorizontalAlign="Center" /

/asp:BoundField

asp:TemplateField HeaderText="系统标识"

ItemTemplate

%# Eval("Function_IsSys").ToString() == "1" ? "系统定义" : "用户自定义"%

/ItemTemplate

HeaderStyle Font-Bold="False" HorizontalAlign="Center" /

ItemStyle HorizontalAlign="Center" /

/asp:TemplateField

asp:BoundField HeaderText="功能描述" DataField="Function_Description"

HeaderStyle HorizontalAlign="Center" Font-Bold="False" /

ItemStyle HorizontalAlign="Center" /

/asp:BoundField

asp:TemplateField HeaderText="操 作"

ItemTemplate

%-- input type="checkbox" id="ckvalue" %#Eval("Function_IsSys").ToString() == "2"? " " :"disabled='disabled'" % name="ckvalue" value='%# Eval("Function_ID") %' //ItemTemplate--%

asp:HyperLink ID="Update" ToolTip="修改" runat="server" NavigateUrl='%#String.Format("ModulFunctionEdit.aspx?id={0}", Eval("FUNCTION_ID")) %'img src="../skins/sky/icon/edt.gif" border="0" /修改 /asp:HyperLink

asp:HyperLink ID="View" Enabled="false" ToolTip="详情" runat="server" NavigateUrl='%#String.Format("ModulFunctionView.aspx?id={0}",Eval("FUNCTION_ID")) %' img src="../skins/sky/icon/layout_content.gif" border="0" /详细 /asp:HyperLink

%#Eval("Function_IsSys").ToString() == "2"?

"asp:HyperLink ID='Delete' Enabled='false' runat='server' ToolTip='删除' NavigateUrl='#' span style='cursor:pointer' onclick=DelInfoById(" + Eval("FUNCTION_ID") + ",XC_Web.Frame.SystemManage.ModulFunction,'/Frame/SystemManage/ModulFunction.aspx')img src='../skins/sky/icon/del.gif' border='0'/删除/span/span/asp:HyperLink" :

"asp:HyperLink ID='Delete' runat='server' NavigateUrl='#' ToolTip='删除' disabled='disabled' img src='../skins/sky/icon/del.gif' border='0'/删除/asp:HyperLink"

%

/ItemTemplate

HeaderStyle Font-Bold="False" /

ItemStyle HorizontalAlign="Center" Width="22%" /

/asp:TemplateField

/Columns

(责任编辑:IT教学网)

更多

相关综合特效文章

推荐综合特效文章