I have an GridView with button "Delete".
I need get value to column or cell of index[3].
But with GridView1.SelectedRow.Cells[3].Text;
it return null.
Someone help me? I do not want use javascript.
My aspx:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" GridLines="None"
CssClass="table table-bordered table-striped">
<Columns>
<asp:BoundField DataField="DisplayName" HeaderText="Display Name" />
<asp:BoundField DataField="UserName" HeaderText="User Name" />
<asp:BoundField DataField="Email" HeaderText="Email" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_OnClick" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
My .cs:
protected void btnDelete_OnClick(object sender, EventArgs e)
{
using (objConexao = new SqlConnection(strStringConexao))
{
SqlConnection oConn = new SqlConnection();
SqlCommand oCommand = new SqlCommand();
string strConn = ConfigurationManager.ConnectionStrings["XXX"].ConnectionString;
oConn.ConnectionString = strConn;
oCommand.Connection = oConn;
oCommand.CommandText = "proc_Delete";
oCommand.CommandType = CommandType.StoredProcedure;
SqlParameter myParam = oCommand.Parameters.Add("@UserRequestor", SqlDbType.NVarChar);
myParam.Value = User;
SqlParameter myParam2 = oCommand.Parameters.Add("@UserName", SqlDbType.NVarChar);
myParam2.Value = GridView1.Columns[3].ToString();
oConn.Open();
oCommand.ExecuteNonQuery();
oConn.Close();
}
}