How to code for GRidview shown content depends on id ?
Hai Friends,
i ve the page aspx like below requirements
departuredate = text box,
from = text box,
to = text box,
travel mode= text box,
request_id = text box(visible false)
add(button)
after the add entire details ll shown on Gridview table.
now my requirement is when the request_id generated depends on the details ll show on GridView.
if the request_id nothing gridview ll shown "no record data found"
how to do that?
Iftikar HussainPosted Jul 26, 2013, 3:37 AM
SELECT @requestId as requestId
Regards,
Iftikar
Rocky RockyPosted Jul 26, 2013, 5:06 AM
After change travel_request its working fine.Thank you so much friend
Iftikar HussainPosted Jul 26, 2013, 4:50 AM
cmd.Parameters.AddWithValue("@departuredate", string.Format("{0:MM/dd/yyyy}", Datepicker.Value));
Regards,
Iftikar
Rocky RockyPosted Jul 26, 2013, 3:50 AM
when i am trying to insert dates via front hand its wont accepting what is the problem in that?
code is already written above "ADD_CLICK".
can you guide me and one more think gridview doestnot show any values.......
what can i do?
protected void ADD_CLICK(object sender, EventArgs e)
{
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);
// cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
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();
}
/// here how to get the request for shall i un marked that or market that date cannot be inserting?
Rocky RockyPosted Jul 26, 2013, 3:32 AM
(
@user varchar(100),
@purpose varchar(100),
@adamt varchar(10),
@status int,
@total varchar(100)
)
as
begin
if not exists (select * from travel_request where user_id=@user and purpose_of_travel=@purpose and advance_amount=@adamt and status_id=@status)
insert into travel_request (user_id,purpose_of_travel,advance_amount,status_id,total_amount) values(@user,@purpose,@adamt,'2',@total)
end
Iftikar HussainPosted Jul 26, 2013, 3:30 AM
Regards,
Iftikar
Rocky RockyPosted Jul 26, 2013, 3:26 AM
your are correct
Iftikar HussainPosted Jul 26, 2013, 3:15 AM
You are doing like this
1. Creating Travel Request (i.e. travel_request table entry)
2. Creating Onward Journey details (i.e. onward_journey table entry)
each travel travel request there will be one entry in the second table
Regards,
Iftikar
Rocky RockyPosted Jul 26, 2013, 3:04 AM
when i choose
select * from onward_journey where request_id= IDENT_current('Travel_request).
after the save the gridview value other login person try to add new details gridview view showing previous gridview value's.
depends upon the person ll show empty doesn't older value in gridview...... how to do that?
Iftikar HussainPosted Jul 26, 2013, 2:46 AM
Regards,
Iftikar
Rocky RockyPosted Jul 26, 2013, 2:26 AM
for The ADD button i made the code like below
protected void ADD_Click(object sender, EventArgs e)
{
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);
cmd.Parameters.AddWithValue("@request", Txtrequest.Text);
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();
}
For My Procedure:
===============
--sp_helptext'insert_journey'
alter procedure Insert_Journey
(
@departuredate datetime,
@from_location varchar(50),
@to_location varchar(50),
@metro nvarchar(50),
@trans_all nvarchar(50),
@mode_of_travel nvarchar(50),
@seat_type nvarchar(50),
@no_of_days int,
@other_details varchar(50),
@status_id int,
@request int
)
as
BEGIN
DECLARE @MaxDate datetime
SELECT @MaxDate = MAX(DepartureDate) FROM onward_journey where request_id=IDENT_CURRENT ('travel_request')
IF(@MaxDate >@departuredate)
begin
RAISERROR('Your error message for departuredate should be greater then maxdate',16,1)
RETURN
END
insert into onward_journey(departuredate,from_location,to_location,metro,trans_all,mode_of_travel,seat_type,no_of_days,other_details,status_id,request_id) values(@departuredate,@from_location,@to_location,@metro,@trans_all,@mode_of_travel,@seat_type,@no_of_days,@other_details,'2',IDENT_CURRENT ('travel_request'))
--set @request= IDENT_CURRENT ('travel_request')
--return @request
end
--
Now My the problem is when i add the values gridview not shown...............
public void binddata()
{
if ((TxtComments.Text == "") && (Txttotal.Text == ""))
{
string req = Txtrequest.Text;
string strquery = "select
onward_journey_id,
convert(varchar, departuredate, 106)as DepartureDate,
from_location,
to_location,
case metro when 'Yes' then 'Yes' else 'No' end as Metro,
case Trans_All when 'Yes' then 'Yes' else 'No' END as transit,
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);
conn.Open();
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());
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";
}
conn.Close();
}
}
above BINDATA() function ll reflect the grid vieaw table what was problem in that?
Iftikar HussainPosted Jul 26, 2013, 2:13 AM
Please provide more details If possible then attach the screen shot.
Regards,
Iftikar
Sunny SharmaPosted Jul 26, 2013, 2:03 AM