Hi sir i have a code which select the GridView row by clicking and select button.
When i run code it give me error on this
The type or namespace name 'NamingContaineras' could not be found
string flightId = ((senderas Button).NamingContaineras GridViewRow).Cells[0].Text;
my code is.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data.SqlClient;
namespace AirportOppsTimeTracker
{
public partial class AllFlights : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
lblUserName.Text = Session["User"].ToString();
string origin = Session["origin"].ToString();
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con = new SqlConnection(conString))
{
using (SqlCommand cmd = new SqlCommand("SELECT * FROM Flights WHERE origin = @origin ", con))
{
cmd.Parameters.AddWithValue("@origin", origin);
con.Open();
gvCustomers.DataSource = cmd.ExecuteReader();
gvCustomers.DataBind();
con.Close();
}
}
}
}
protected void OnSelect(object sender, EventArgs e)
{
// string sessionId = Session.SessionID;
string userId = Session["User"].ToString();
string status ="Active";
string flightId = ((senderas Button).NamingContaineras GridViewRow).Cells[0].Text;
string conString = ConfigurationManager.ConnectionStrings["constr"].ConnectionString;
using (SqlConnection con =new SqlConnection(conString))
{
using (SqlCommand cmd =new SqlCommand("INSERT INTO session VALUES ( @userId, @flightid, @status)", con))
{
// cmd.Parameters.AddWithValue("@SessionId", sessionId);
cmd.Parameters.AddWithValue("@userid", userId);
cmd.Parameters.AddWithValue("@flightid", flightId);
cmd.Parameters.AddWithValue("@status", status);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
Response.Redirect("TimeTrackerpage.aspx");
}
}
}
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:BoundField HeaderText="FlightNo" DataField="flight_no" />
<asp:BoundField HeaderText="Name" DataField="flight_date" />
<asp:BoundField HeaderText="Origin" DataField="origin" />
<asp:TemplateField>
<ItemTemplate>
<asp:Button ID="btnSelect" runat="server" Text="Select" OnClick="OnSelect"/>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<asp:Label ID="lblUserName" runat="server"></asp:Label>