asp:commandfield showselectbutton
from https://www.weblio.jp/content/CommandField.ShowSelectButton+%E3%83%97%E3%83%AD%E3%83%91%E3%83%86%E3%82%A3
protected void CustomersGridView_SelectedIndexChanged(object sender, EventArgs e)
{ String companyName = CustomersGridView.SelectedRow.Cells[2].Text;
}
<%@ Page language="C#" %> <html> <body> <form runat="server"> <h3>CommandField Example</h3> <asp:Label id="Message" forecolor="Red" runat="server"/> <asp:gridview id="CustomersGridView" datasourceid="CustomersSqlDataSource" autogeneratecolumns="false" datakeynames="CustomerID" onselectedindexchanged="CustomersGridView_SelectedIndexChanged" runat="server"> <columns> <asp:commandfield showselectbutton="true" headertext="Select Customer"/> <asp:boundfield datafield="CustomerID" headertext="Customer ID" /> <asp:boundfield datafield="CompanyName" headertext="Company Name"/> <asp:boundfield datafield="Address" headertext="Address"/> <asp:boundfield datafield="City" headertext="City"/> <asp:boundfield datafield="PostalCode" headertext="ZIP Code"/> <asp:boundfield datafield="Country" headertext="Country"/> </columns> </asp:gridview> <!-- This example uses Microsoft SQL Server and connects --> <!-- to the Northwind sample database. Use an ASP.NET --> <!-- expression to retrieve the connection string value --> <!-- from the Web.config file. --> <asp:sqldatasource id="CustomersSqlDataSource" selectcommand="Select [CustomerID], [CompanyName], [Address], [City], [PostalCode], [Country] From [Customers]" connectionstring="<%$ ConnectionStrings:NorthWindConnectionString%>" runat="server"> </asp:sqldatasource> </form> </body> </html>
留言
張貼留言