ButtonField 对象在 GridView 控件中如合使用
来源:互联网 发布:浙江网络发票真伪查询 编辑:程序博客网 时间:2024/05/29 19:01
下面的代码示例演示如何使用 ButtonField 对象显示 GridView 控件中的一列命令按钮。
Visual Basic
复制代码
<%@ Page language="VB" %>
<script runat="server">
Sub CustomersGridView_RowCommand()Sub CustomersGridView_RowCommand(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)
' 如果多個使用多個buttonfield,利用CommandName來確定那個buttonfield被點擊.
If e.CommandName = "Select" Then
'轉換列的索引放進CommandArgument
Dim index As Integer = Convert.ToInt32(e.CommandArgument)
' 從appropriate獲得所選作者的姓
' cell in the GridView control.
Dim selectedRow As GridViewRow = CustomersGridView.Rows(index)
Dim contactCell As TableCell = selectedRow.Cells(1)
Dim contact As String = contactCell.Text
' 顯示所選作者.
Message.Text = "You selected " & contact & "."
End If
End Sub
</script>
<html>
<body>
<form id="Form1" runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%___FCKpd___0nbsp;ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
C#
<%@ Page language="C#" %>
<script runat="server">
void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
...{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Select")
...{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Get the last name of the selected author from the appropriate
// cell in the GridView control.
GridViewRow selectedRow = CustomersGridView.Rows[index];
TableCell contactName = selectedRow.Cells[1];
string contact = contactName.Text;
// Display the selected author.
Message.Text = "You selected " + contact + ".";
}
}
</script>
<html>
<body>
<form runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
<script runat="server">
void CustomersGridView_RowCommand(Object sender, GridViewCommandEventArgs e)
...{
// If multiple ButtonField column fields are used, use the
// CommandName property to determine which button was clicked.
if(e.CommandName=="Select")
...{
// Convert the row index stored in the CommandArgument
// property to an Integer.
int index = Convert.ToInt32(e.CommandArgument);
// Get the last name of the selected author from the appropriate
// cell in the GridView control.
GridViewRow selectedRow = CustomersGridView.Rows[index];
TableCell contactName = selectedRow.Cells[1];
string contact = contactName.Text;
// Display the selected author.
Message.Text = "You selected " + contact + ".";
}
}
</script>
<html>
<body>
<form runat="server">
<h3>ButtonField Example</h3>
<asp:label id="Message"
forecolor="Red"
runat="server"/>
<!-- Populate the Columns collection declaratively. -->
<asp:gridview id="CustomersGridView"
datasourceid="CustomersSqlDataSource"
autogeneratecolumns="false"
onrowcommand="CustomersGridView_RowCommand"
runat="server">
<columns>
<asp:buttonfield buttontype="Button"
commandname="Select"
headertext="Select Customer"
text="Select"/>
<asp:boundfield datafield="CompanyName"
headertext="Company Name"/>
<asp:boundfield datafield="ContactName"
headertext="Contact Name"/>
</columns>
</asp:gridview>
<!-- This example uses Microsoft SQL Server and connects -->
<!-- to the Northwind sample database. -->
<asp:sqldatasource id="CustomersSqlDataSource"
selectcommand="Select [CustomerID], [CompanyName], [ContactName], [ContactTitle] From [Customers]"
connectionstring="<%$ ConnectionStrings:NorthWindConnection%>"
runat="server">
</asp:sqldatasource>
</form>
</body>
</html>
- ButtonField 对象在 GridView 控件中如合使用
- gridview的ButtonField
- gridview buttonfield用法
- 在GridView控件中使用TemplateField
- 在GridView控件中使用TemplateField
- 使用JavaScript在客户端验证GridView控件
- 网格控件GridView在Android中的使用
- 在GridView控件中使用TemplateField
- 网格控件GridView在Android中的使用
- 使用GridView中的按钮(ButtonField或TemplateField里面的按钮)控制UpdatePanel的更新
- 为GridView 加按钮列之后,(ButtonField)
- 在ASP.NET的GridView(CommandField、ButtonField、ItemTemplate)裡的刪除Button加入Confirm的用法
- 在ASP.NET的GridView(CommandField、ButtonField、ItemTemplate)里的刪除Button加入Confirm的用法
- GridView控件使用经验
- GridView控件使用常见问题
- GridView控件使用经验
- gridview控件使用
- Gridview控件使用详解
- writehtml方法中使用到的一个类
- Google、迅雷与李开复、周鸿祎的那点破事
- 精解PCI Express
- 我的开发板的LED流水灯接口
- 是需要,還是想要?
- ButtonField 对象在 GridView 控件中如合使用
- 关于SAP的事务提交和回滚(LUW)
- 音频软件 Advanced WMA Workshop
- 什么是web标准
- 在PHP中全面阻止SQL注入式攻击之二
- VSS+Vs2003使用手册
- sprintf你知道多少
- 数据库中数据挖掘的基本技术介绍
- 视频网站热浪消退 垂直门户成新焦点