Hai Friends,
I ve the travel page
save(button)
1)departuredate=jquerydatepicker
2)from = textbox
3)to = textbox
4) Mode = dropdown
5)no.of.days = textbox
ADD(button after press the add entire details ll show on gridview).
after fill these page employee press save button means ll go to "HOME.aspx" in draft items.
i made here first departuredate(link button) from and to place ll shown on Draft ITEMS.
now my requirements is
I)when i choose the draft items ll go travel page and ll show deatils what i am save?
II)if i am make new request in above fields means gridview ll show empty not show the old vaules in textbox?
how to that?
Loading
Rocky RockyPosted Jul 19, 2013, 5:26 AM
i ve added images below
1)beforedrft => when i entering fields and make before draft in "travel.aspx"
2) draft=> if choose the draft items ll redirect into above aspx .
3) newrequest => if i m make new request grid view ll show empty.
Rocky RockyPosted Jul 19, 2013, 3:49 AM
Travel plan.aspx
=============
My aspx code for ADD:
===================
protected void ADD_Click(object sender, EventArgs e)
{
if (TxtFm.Text == "")
{
Response.Write("");
}
if (TxtTo.Text == "")
{
Response.Write("");
}
if (DDL_Metro.SelectedIndex == 0)
{
Response.Write("");
}
if (DDL_trans.SelectedIndex == 0)
{
Response.Write("");
}
if (DDL_ModeOfTravel.SelectedIndex == 0)
{
Response.Write("");
}
if (DDL_SeatType.SelectedIndex == 0)
{
Response.Write("");
}
if (TxtNo.Text == "")
{
Response.Write("");
}
if ((Datepicker.Text != "") && (TxtNo.Text != "") && (DDL_SeatType.Text != "") && (DDL_ModeOfTravel.Text != "") && (TxtTo.Text != "") && (TxtFm.Text != "") && (DDL_Metro.Text != "") && (DDL_trans.Text != "") && (TxtNo.Text != ""))
{
//DateTime de = Datepicker.Text;
//DateTime de = Convert.ToDateTime(Datepicker.Text);
//Session["Datepicker.Text"] = de;
//DateTime newdr = DateTime.Parse(readerHasRows);
//string sql;
try
{
//string sql = "insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2')";
SqlCommand cmd = new SqlCommand("[Insert_Journey]", conn);
datecheck();
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@departuredate", Datepicker.Text);
cmd.Parameters.AddWithValue("@from_location", TxtFm.Text);
cmd.Parameters.AddWithValue("@to_location", TxtTo.Text);
cmd.Parameters.AddWithValue("@metro", DDL_Metro.Text);
cmd.Parameters.AddWithValue("@trans_all", DDL_trans.Text);
cmd.Parameters.AddWithValue("@mode_of_travel", DDL_ModeOfTravel.Text);
cmd.Parameters.AddWithValue("@seat_type", DDL_SeatType.Text);
cmd.Parameters.AddWithValue("@no_of_days", TxtNo.Text);
cmd.Parameters.AddWithValue("@other_details", Txtothrdet.Text);
cmd.Parameters.AddWithValue("@status_id", Txtstts.Text);
// int count = cmd.ExecuteNonQuery();
conn.Open();
cmd.ExecuteNonQuery();
DateTime val = new DateTime();
DateTime b = new DateTime();
val = Convert.ToDateTime(Datepicker.Text);
b = val.AddDays(Convert.ToInt32(TxtNo.Text));
Datepicker.Text = b.ToString();
binddata();
}
catch (System.Data.SqlClient.SqlException ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
catch (System.Exception ex)
{
Console.WriteLine("Source: " + ex.Source);
Console.WriteLine("Exception Message: " + ex.Message);
}
finally
{
if (conn.State == ConnectionState.Open)
{
Console.WriteLine("Finally block closing the connection");
conn.Close();
}
}
//string st = "select convert(varchar, departuredate, 103)as DepartureDate , from_location as 'From' ,to_location 'To', metro,trans_all as Trans,mode_of_travel as ModeOfTravel,seat_type as Seat, no_of_days as Numdays, other_details as OtherDetails from onward_journey";
//SqlDataAdapter de = new SqlDataAdapter(st, conn);
//DataTable dtStore = new DataTable();
//de.Fill(dtStore);
//grdvStore.DataSource = dtStore.DefaultView;
//grdvStore.DataBind();
//Datepicker.Enabled = false;
DDL_Metro.SelectedIndex = 0;
DDL_trans.SelectedIndex = 0;
DDL_ModeOfTravel.SelectedIndex = 0;
DDL_SeatType.SelectedIndex = 0;
TxtFm.Text = "";
TxtTo.Text = "";
TxtNo.Text = "";
Txtothrdet.Text = "";
}
}
My code for GridvIew:
================
public void binddata()
{
string strquery = "select request_id,onward_journey_id,convert(varchar, departuredate, 106)as DepartureDate,from_location,to_location, case metro when 'Y' then 'Yes' else 'No' END as Metro, case Trans_All when 'Y' then 'Yes' else 'No' END as transit,case when mode_of_travel like 'Ai%' then mode_of_travel when mode_of_travel like 'Tr%' then mode_of_travel when mode_of_travel like 'Bu%' then mode_of_travel when mode_of_travel like 'Ca%' then mode_of_travel when mode_of_travel like 'Au%' then mode_of_travel when mode_of_travel like 'lo%' then mode_of_travel end as Mode,case when mode_of_travel like ('ai%') then seat_type when mode_of_travel like ('tra%') then seat_type when mode_of_travel like ('Bu%') then seat_type when mode_of_travel like ('ca%') then seat_type when mode_of_travel like ('au%') then seat_type when mode_of_travel like ('loc%') then seat_type end as SEAT,no_of_days as noofdays,other_details from onward_journey where request_id=IDENT_CURRENT('travel_request ')order by departuredate";
SqlCommand cmd = new SqlCommand(strquery, conn);
SqlDataAdapter da = new SqlDataAdapter(cmd);
ds.Clear();
da.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
else
{
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
GridView1.DataSource = ds;
GridView1.DataBind();
int columncount = GridView1.Rows[0].Cells.Count;
GridView1.Rows[0].Cells.Clear();
GridView1.Rows[0].Cells.Add(new TableCell());
GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
GridView1.Rows[0].Cells[0].Text = "No Records Found";
}
}
Home page:
============
<%#Eval("request_id")%>
in.cs
====
public void draftdata()
{
//string strquet = "select convert(varchar,min(a.departuredate),106)Departuredate,b.purpose_of_travel as purpose,b.total_amount ,a.request_id from onward_journey a inner join travel_request b on a.request_id=b.request_id group by b.purpose_of_travel,b.total_amount,a.request_id";
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("drft", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username",uname);
SqlDataAdapter da = new SqlDataAdapter(cmd);
//SqlDataReader rdrData;
ds.Clear();
da.Fill(ds);
con.Open();
cmd.ExecuteNonQuery();
//rdrData = cmd.ExecuteReader();
if (ds.Tables.Count > 0)
{
for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
{
GridView1.DataSource = ds;
GridView1.DataBind();
}
}
else
{
GridView1.DataSource = null;
GridView1.DataBind();
}
con.Close();
}
//protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
//{
// if(GridView1.SelectedRow.co
//}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{
int request = Convert.ToInt32(Request.QueryString["request_id"]);
Response.Redirect("Travel.aspx?request_id=" + request);
}
Iftikar HussainPosted Jul 19, 2013, 3:12 AM
Regards,
Iftikar
Rocky RockyPosted Jul 19, 2013, 3:10 AM
i done everythink i 'm struck there when i save in travel.aspx the gridvalue it ll show on HOME.aspx ve the column draft items there ll be shown.
if i choose the draft items ll go travel aspx. with i entered value how to show that?
Iftikar HussainPosted Jul 19, 2013, 1:47 AM
Please refer the below link
http://www.aspdotnet-suresh.com/2011/02/how-to-inserteditupdate-and-delete-data.html
Regards,
Iftikar