![]() |
delete button and variable in NavigateUrl in VS2005
Hi,
I have create a data grid view with delete button in VS 2005. so far I have able to display the data from database, howvever, there are two issues 1)I do not know how to call the delete command. 2), In my data grid,<asp:HyperLinkField DataTextField="UserName" HeaderText="View Website" NavigateUrl="http://www.msn.org/" & text.UserName & "" Target="_blank">, it doesn't work, I want that url has the username as variable, anyone can help me out, thanks in advance. below is my code, <%@ Page Language="VB" Debug="true" %> <script language="VB" runat="server" > Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs) If Not Page.IsPostBack Then End If End Sub Sub GridView1_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs ) Handles GridView1.RowCommand Dim RecordID As Button Dim myConnection As String = ConfigurationManager.ConnectionStrings("Connection String").ConnectionString Dim strSQL As String = "DELETE FROM eMints WHERE RecordID = " & RecordID & "" Response.Write(strSQL) Dim Connection As New Data.SqlClient.SqlConnection(myConnection) Dim myCommand As New Data.SqlClient.SqlCommand(strSQL, Connection) Connection.Open() myCommand.ExecuteNonQuery() Connection.Close() End Sub </script> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" > <head runat="server"> <title>eMint Admin</title> </head> <body> <form id="form1" runat="server"> <div> <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [RecordID], [LastName], [FirstName], [Location], [Phone], [Status], [UserName] FROM [eMints] ORDER BY [LastName]"> </asp:SqlDataSource> </div> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="RecordID" DataSourceID="SqlDataSource1" Font-Names="Arial"> <Columns> <asp:BoundField DataField="RecordID" HeaderText="RecordID" InsertVisible="False" ReadOnly="True" SortExpression="RecordID" Visible="False" /> <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> <asp:BoundField DataField="Location" HeaderText="Location" SortExpression="Location" /> <asp:BoundField DataField="Phone" HeaderText="Phone" SortExpression="Phone" /> <asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" /> <asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" /> <asp:HyperLinkField DataTextField="UserName" HeaderText="View Website" NavigateUrl="http://www.msn.org/" & text.UserName & "" Target="_blank"> <HeaderStyle Font-Underline="True" ForeColor="Blue" /> </asp:HyperLinkField> <asp:CommandField ButtonType="Button" HeaderText="Remove User" ShowDeleteButton="True"> <HeaderStyle Font-Names="Arial" Font-Size="Medium" Font-Underline="True" ForeColor="Blue" /> <ItemStyle ForeColor="White" /> <ControlStyle ForeColor="Red" /> </asp:CommandField> </Columns> <RowStyle Font-Size="Smaller" /> <EditRowStyle BackColor="White" ForeColor="White" /> <HeaderStyle Font-Size="Medium" /> <AlternatingRowStyle BackColor="#FFFFC0" /> </asp:GridView> </form> </body> </html> |
| All times are GMT. The time now is 01:40 AM. |
Powered by vBulletin®. Copyright ©2000 - 2013, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.