943,950 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 25568
  • C# RSS
You are currently viewing page 1 of this multi-page discussion thread
Feb 11th, 2008
0

Textbox and button visible true or false problem

Expand Post »
hi
I am creating travels project, in left part of my datagrid of my default page i placed all the products such as india tour ,world tour etc and if v click any product it will redirect to itennary page according to their ID's
my problem is i inserted new product as Hotel Booking and i want to place textbox and a button in the itenary page and if v click india tour or world tour i want those textbox and button should be not visible and if v click Hotel booking then those textbox and button should visible
Please solve my problem its urgent.
Thank you in advance
raghu
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Feb 11th, 2008
0

Re: Textbox and button visible true or false problem

c# Syntax (Toggle Plain Text)
  1. Button2.Visible = false; // to hide button
  2. textBox1.Visible = false; // to hide textbox
  3.  
  4. Button2.Visible = true; // to show button
  5. textBox1.Visible = false; // to show textbox
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,142 posts
since Nov 2007
Feb 11th, 2008
-1

Re: Textbox and button visible true or false problem

Thanks for your reply Jx_man
i know that codding but i want codding for particular selected product in datagrid
just read my question properly please
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Feb 11th, 2008
0

Re: Textbox and button visible true or false problem

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.
Last edited by hollystyles; Feb 11th, 2008 at 9:20 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Feb 11th, 2008
0

Re: Textbox and button visible true or false problem

Thanks holly for your reply
with in the itenary page i placed datagrid and the values has been populated from dadatbase according to the selected product whether it is a India tour or world tour
now i placed hotel booking in the product list and when i click i want to place all the texbox and button

just look at my codding

if (!IsPostBack)
{
if (Request.QueryString["CatId"] != null)
{
Session["catid"] = Request.QueryString["CatId"].ToString();
}
else
{
Session["catid"] = "0";
}
fillgrid();

private void fillgrid()
{

DataSet ds = Travel_Product1.return_travel_product_bycatid(Convert.ToInt32(Session["catid"]));
if (ds != null)
{
if (ds.Tables[0].Rows.Count > 0)
{
dgprodlist.DataSource = ds;
dgprodlist.DataBind();


}
}
}

please try to solve my proble its very urgent
Thank you in advance
raghu
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Feb 11th, 2008
0

Re: Textbox and button visible true or false problem

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

C# Syntax (Toggle Plain Text)
  1. <asp:DataGrid ID="dgprodlist" Runat="server" AutoGenerateColumns="False">
  2. <Columns>
  3. <asp:BoundColumn HeaderText="Product" DataField="Product"></asp:BoundColumn>
  4. <asp:TemplateColumn>
  5. <ItemTemplate>
  6. <asp:TextBox ID="txtText" Runat="server"></asp:TextBox>
  7. &nbsp;
  8. <asp:Button ID="btnButton" Runat="server" Text="Button"></asp:Button>
  9. </ItemTemplate>
  10. </asp:TemplateColumn>
  11.  
  12. </Columns>
  13. </asp:DataGrid>

C# Syntax (Toggle Plain Text)
  1. public class itinerary : System.Web.UI.Page
  2. {
  3. protected System.Web.UI.WebControls.DataGrid dgprodlist;
  4.  
  5. //set up some data
  6. private string[] products = {"Product 1","Product 2","Hotel Booking"};
  7. private DataTable prodList = new DataTable();
  8.  
  9. private void Page_Load(object sender, System.EventArgs e)
  10. {
  11. // Put user code to initialize the page here
  12. if(!IsPostBack)
  13. {
  14. //Add a column (I don't have your database so I have to mock it up)
  15. prodList.Columns.Add("Product");
  16.  
  17. //add some rows
  18. for(int i = 0; i < 3; ++i)
  19. {
  20. DataRow row = prodList.NewRow();
  21. row[0] = products[i];
  22. prodList.Rows.Add(row);
  23. }
  24.  
  25. //Bind the data
  26. dgprodlist.DataSource = prodList;
  27. dgprodlist.DataBind();
  28.  
  29. }
  30. }
  31.  
  32. #region Web Form Designer generated code
  33. override protected void OnInit(EventArgs e)
  34. {
  35. //
  36. // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  37. //
  38. InitializeComponent();
  39. base.OnInit(e);
  40. }
  41.  
  42. /// <summary>
  43. /// Required method for Designer support - do not modify
  44. /// the contents of this method with the code editor.
  45. /// </summary>
  46. private void InitializeComponent()
  47. {
  48. this.Load += new System.EventHandler(this.Page_Load);
  49. this.dgprodlist.ItemDataBound += new DataGridItemEventHandler(dgprodlist_ItemDataBound); //Wire up the event. Fires on row creation during DataBind()
  50. }
  51. #endregion
  52.  
  53. private void dgprodlist_ItemDataBound(object sender, DataGridItemEventArgs e)
  54. {
  55. //Test for rows, don't want to execute code on header item that will cause an exception.
  56. if(e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
  57. {
  58. //Get a reference to the textbox and button control
  59. TextBox tb = (TextBox)e.Item.Cells[1].FindControl("txtText");
  60. Button b = (Button)e.Item.Cells[1].FindControl("btnButton");
  61.  
  62. //If it's the hotel booing product show the controls, else hide them
  63. if(e.Item.Cells[0].Text == "Hotel Booking")
  64. {
  65. tb.Visible = true;
  66. b.Visible = true;
  67. }
  68. else
  69. {
  70. tb.Visible = false;
  71. b.Visible = false;
  72. }
  73. }
  74. }
  75. }
Last edited by hollystyles; Feb 11th, 2008 at 10:57 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Feb 12th, 2008
0

Re: Textbox and button visible true or false problem

Thanks holly for that codding but you almost got my problem

yes indian tours,world tours and even hotel booking is also category,
now, when i click india tour or world tour it just redirect to itenary page and display images and text in datalist from database according to their categories ID, up to here its running perfectly.
my problem is when i click hotel booking it should redirect to the same itenary page and there i want textbox and buttons
and those textbox and button should be visible false when when i click india tour or world tour and it should visible true when i click hotel booking.

I hope you may understand,
by the way, i dont want to display textbox and button in the datagrid

Thank you in advance
raghu
Last edited by raghu.8; Feb 12th, 2008 at 6:25 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Feb 12th, 2008
0

Re: Textbox and button visible true or false problem

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 ??????
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005
Feb 12th, 2008
0

Re: Textbox and button visible true or false problem

just look at my coding where i written in the page load event
C# Syntax (Toggle Plain Text)
  1. protected void Page_Load()
  2. {
  3. int id = int.Parse(Request.QueryString["ID"]);
  4.  
  5. if (id == "hotel booking") //etc...
  6. {
  7. TextBox1.Visible = true;
  8. Button1.Visible = true;
  9. }
  10. else
  11. {
  12. TextBox1.Visible = false;
  13. Button1.Visible = false;
  14. }

but i am getting error
raghu
Last edited by raghu.8; Feb 12th, 2008 at 6:36 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
raghu.8 is offline Offline
40 posts
since Nov 2007
Feb 12th, 2008
0

Re: Textbox and button visible true or false problem

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.
Last edited by hollystyles; Feb 12th, 2008 at 6:44 am.
Reputation Points: 262
Solved Threads: 68
Veteran Poster
hollystyles is offline Offline
1,181 posts
since Feb 2005

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Shell() command line
Next Thread in C# Forum Timeline: ComboBox Item selection





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC