Button2.Visible = false; // to hide button
textBox1.Visible = false; // to hide textbox
Button2.Visible = true; // to show button
textBox1.Visible = false; // to show textbox
Jx_Man
Nearly a Senior Poster
3,328 posts since Nov 2007
Reputation Points: 1,372
Solved Threads: 444
You haven't given us enough information to give you specific codeing. How do you know what itinery to show in the itinery page? Are you using the query string or session variable? Codeing will be different depending.
The only coding that would always be the same is the snippet Jx_Man gave, inside some kind of if statement, that works out from the ID if the selected item, whether it's a hotel booking or not.
And I would guess you'd put that into the Page_Load event of the itinery page.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
I'm still not entirely sure what you want to do. I take it english is not your first language?
Are india tour and world tour catagories ?
So I choose a category, then I see a datagrid of tour products, one of which is a hotel booking ? So hotel booking is in the datagrid?
A textbox and button should appear in a datagrid column oposite only the hotel booking product, to the right hand side?
Use the OnItemDataBound event of the datagrid, use the event args to determine if the row is a hotel booking, make the textbox and button visible
<asp:DataGrid ID="dgprodlist" Runat="server" AutoGenerateColumns="False">
<Columns>
<asp:BoundColumn HeaderText="Product" DataField="Product"></asp:BoundColumn>
<asp:TemplateColumn>
<ItemTemplate>
<asp:TextBox ID="txtText" Runat="server"></asp:TextBox>
<asp:Button ID="btnButton" Runat="server" Text="Button"></asp:Button>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:DataGrid>
public class itinerary : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataGrid dgprodlist;
//set up some data
private string[] products = {"Product 1","Product 2","Hotel Booking"};
private DataTable prodList = new DataTable();
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
if(!IsPostBack)
{
//Add a column (I don't have your database so I have to mock it up)
prodList.Columns.Add("Product");
//add some rows
for(int i = 0; i < 3; ++i)
{
DataRow row = prodList.NewRow();
row[0] = products[i];
prodList.Rows.Add(row);
}
//Bind the data
dgprodlist.DataSource = prodList;
dgprodlist.DataBind();
}
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.Load += new System.EventHandler(this.Page_Load);
this.dgprodlist.ItemDataBound += new DataGridItemEventHandler(dgprodlist_ItemDataBound); //Wire up the event. Fires on row creation during DataBind()
}
#endregion
private void dgprodlist_ItemDataBound(object sender, DataGridItemEventArgs e)
{
//Test for rows, don't want to execute code on header item that will cause an exception.
if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
//Get a reference to the textbox and button control
TextBox tb = (TextBox)e.Item.Cells[1].FindControl("txtText");
Button b = (Button)e.Item.Cells[1].FindControl("btnButton");
//If it's the hotel booing product show the controls, else hide them
if(e.Item.Cells[0].Text == "Hotel Booking")
{
tb.Visible = true;
b.Visible = true;
}
else
{
tb.Visible = false;
b.Visible = false;
}
}
}
}
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
Right, so just set the visible properties of the necessary controls in the page load event handler of itenary.aspx
I don't get what the problem is ??????
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
Post the error then, I 'm afraid I left my crystal ball at home. :)
Well actually I can hazard a guess. You cast the QueryString variable to integer, then you try and comapre it to a string lilteral ??
if (id == "hotel booking")
is your problem, id is an integer variable, "hotel booking" is a string literal... duh!
options:
Pass "hotel booking" in the QueryString instead or aditionally
Look up the catagory text in the DB using the id
hard code the id (bad bad bad...)
What should really do is make a ups_IsHotelBooking stored procedure in the DB passing your id to it and get it to return 1 for true and 0 for false and set the textbox and button visibility accordingly.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
That's right the variable id is an integer, "world tour" is a string literal you cannot apply the == operator to these different types.
I can see you are either very very green or a forum troll. If the former you need to get a book on basic programming. One that starts from the beginning explaining types and stuff. If the latter I'm done here.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
You're very close. You have the ID, you need a function in itenary.aspx.cs you can pass the ID too, the function should look the ID up and see if it's the hotel booking catagory and return true or false
public class itinery
{
//all your existing code blah...
private bool IsHotelBooking( int catId)
{
//connect to db pass catId as parameter
//somrthing like string catName = command.ExecuteScalar();
if(catName == "hotel booking")
return true;
else
return false;
}
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
still i am getting the same error,when i given hotel booking ID
Don't put the hotel booking id in quotes (I'm guessing that's what you've done). And hard coding an ID into your program logic is very poor, but I guess there's time for that later when you've learned more.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68
I do understand. But yes you can attach it. Click the Go Advanced button below the reply box. You'll get a bigger editor. SCroll the page down a bit and there's a manage attachments button.
hollystyles
Veteran Poster
1,182 posts since Feb 2005
Reputation Points: 262
Solved Threads: 68