Получить текст ASP.NET HyperLinkField в GridView

Я пытаюсь получить текст HyperLinkField в событии OnRowDelete GridView (текст HyperLinkField является первичным ключом строки, которую я хочу удалить). Я понимаю, что вы не можете получить текст, используя код, который я разместил ниже; он работает только для BoundFields (для HyperLinkFields строка ""). Но мне не удалось найти рабочего ответа на получение этого текста. Как мне получить отображаемый текст из HyperLinkField? (VS2010 с ASP.NET 4.0 и C #)

Спасибо за чтение!

Дизайн GridView

        <asp:GridView ID="teamGridView" runat="server" CssClass="gridView" RowStyle-CssClass="rowStyle"
        AlternatingRowStyle-CssClass="altRowStyle" HeaderStyle-CssClass="viewsHeader"
        OnRowEditing="Team_OnRowEditing" OnRowDeleting="Team_OnRowDeleting" OnRowUpdating="Team_OnRowUpdating"
        OnRowCancelingEdit="Team_OnRowCancelingEdit">
        <Columns>
            <asp:HyperLinkField HeaderText="Team Name" DataTextField="Team Name" DataNavigateUrlFields="Team Name"
                DataNavigateUrlFormatString="Teams.aspx?Team_Name={0}" />
            <asp:BoundField HeaderText="Team Captain" DataField="Team Captains" />
            <asp:CommandField Visible="false" HeaderText="Commands" ShowEditButton="true" ShowDeleteButton="true" />
        </Columns>
    </asp:GridView>

Код заполнения GridView

    using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["***"].ConnectionString))
        {
            // Initialize GridView and data
            teamGridView.AutoGenerateColumns = false;
            if (Convert.ToInt32(Session["UserLevel"]) > 0)
            {

                teamGridView.Columns[2].Visible = true;
            }
            SqlDataAdapter teamDataAdapter = new SqlDataAdapter();
            DataSet teamDataSet = new DataSet();
            if (Request["Team_Name"] == null)
            {
                // Show the list of teams if no specific team is requested
                teamDataAdapter.SelectCommand = new SqlCommand("[Team Select]", connection);
                teamDataAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
                teamDataAdapter.Fill(teamDataSet);
                teamGridView.DataSource = teamDataSet;
                teamGridView.DataBind();
            }
}

Код удаления GridView OnRow

        using (SqlConnection connection = new SqlConnection(WebConfigurationManager.ConnectionStrings["***"].ConnectionString))
    {
        SqlCommand teamDeleteCommand = new SqlCommand("[Team Delete]", connection);
        teamDeleteCommand.CommandType = CommandType.StoredProcedure;
        teamDeleteCommand.Parameters.Add("TeamName", SqlDbType.NVarChar, 50);
        teamDeleteCommand.Parameters[0].Value = teamGridView.Rows[e.RowIndex].Cells[0].Text;
        Response.Write(teamDeleteCommand.Parameters[0].Value);
        try
        {
            connection.Open();
            teamDeleteCommand.ExecuteNonQuery();
        }
        catch (SqlException ex)
        {
            throw new Exception("Team Deletion Error");
        }
    }
6
задан Alex Mullans 3 March 2011 в 05:34
поделиться