Textbox and button visible true or false problem

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2007
Posts: 40
Reputation: raghu.8 is an unknown quantity at this point 
Solved Threads: 0
raghu.8 raghu.8 is offline Offline
Light Poster

Textbox and button visible true or false problem

 
0
  #1
Feb 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Textbox and button visible true or false problem

 
0
  #2
Feb 11th, 2008
  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
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 40
Reputation: raghu.8 is an unknown quantity at this point 
Solved Threads: 0
raghu.8 raghu.8 is offline Offline
Light Poster

Re: Textbox and button visible true or false problem

 
-1
  #3
Feb 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Textbox and button visible true or false problem

 
0
  #4
Feb 11th, 2008
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 40
Reputation: raghu.8 is an unknown quantity at this point 
Solved Threads: 0
raghu.8 raghu.8 is offline Offline
Light Poster

Re: Textbox and button visible true or false problem

 
0
  #5
Feb 11th, 2008
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
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Textbox and button visible true or false problem

 
0
  #6
Feb 11th, 2008
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

  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>

  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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 40
Reputation: raghu.8 is an unknown quantity at this point 
Solved Threads: 0
raghu.8 raghu.8 is offline Offline
Light Poster

Re: Textbox and button visible true or false problem

 
0
  #7
Feb 12th, 2008
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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Textbox and button visible true or false problem

 
0
  #8
Feb 12th, 2008
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 ??????
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 40
Reputation: raghu.8 is an unknown quantity at this point 
Solved Threads: 0
raghu.8 raghu.8 is offline Offline
Light Poster

Re: Textbox and button visible true or false problem

 
0
  #9
Feb 12th, 2008
just look at my coding where i written in the page load event
  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.
Reply With Quote Quick reply to this message  
Join Date: Feb 2005
Posts: 1,181
Reputation: hollystyles will become famous soon enough hollystyles will become famous soon enough 
Solved Threads: 67
hollystyles's Avatar
hollystyles hollystyles is offline Offline
Veteran Poster

Re: Textbox and button visible true or false problem

 
0
  #10
Feb 12th, 2008
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.
==========================================
Yadda yadda yadda...
Web junky, fevered monkey
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC