Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. help to get value of a dynamic tabelcell

help to get value of a dynamic tabelcell

Scheduled Pinned Locked Moved ASP.NET
visual-studiotestingbeta-testinghelp
12 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L led mike

    michael_jhons wrote:

    i tried "tabel.Rows[1].Cells[1].Text"

    michael_jhons wrote:

    i tried tr.Cells[1].Controls[0]

    Why would you try both of those? Don't you know what you put in the cells? :confused:

    led mike

    M Offline
    M Offline
    michael_jhons
    wrote on last edited by
    #3

    Dear Mike maby i miss-explained what i want to do, i have a table which contain a checkBox on the first cell of each TableRow, so foreach tableRow i'm checking if the the first cell is checked i read the value of the second cell so i can use it to delete A certain row from my database, so i must read the value. please if you have an answer of my question, help me thank you for your concern

    L 1 Reply Last reply
    0
    • M michael_jhons

      Dear Mike maby i miss-explained what i want to do, i have a table which contain a checkBox on the first cell of each TableRow, so foreach tableRow i'm checking if the the first cell is checked i read the value of the second cell so i can use it to delete A certain row from my database, so i must read the value. please if you have an answer of my question, help me thank you for your concern

      L Offline
      L Offline
      led mike
      wrote on last edited by
      #4

      michael_jhons wrote:

      so i must read the value.

      What value? You still have not posted what you put in the Cell that you want to read? Don't you know?

      led mike

      M 1 Reply Last reply
      0
      • L led mike

        michael_jhons wrote:

        so i must read the value.

        What value? You still have not posted what you put in the Cell that you want to read? Don't you know?

        led mike

        M Offline
        M Offline
        michael_jhons
        wrote on last edited by
        #5

        the table is already populated its full of values i want to retreive that value. here's the code:

        foreach(TableRow tr in TbTariffTb.Rows)
        {
        TableCell cell = tr.Cells[0];
        TableCell celCli=tr.Cells[1];

        foreach (Control control in cell.Controls )
        {

        CheckBox checkBox = control as CheckBox;
        if (checkBox != null)
        {
        if (checkBox.Checked)
        {
        //retreive the value of tr.Cells[1]
        }
        }
        }

        }

        L H 2 Replies Last reply
        0
        • M michael_jhons

          the table is already populated its full of values i want to retreive that value. here's the code:

          foreach(TableRow tr in TbTariffTb.Rows)
          {
          TableCell cell = tr.Cells[0];
          TableCell celCli=tr.Cells[1];

          foreach (Control control in cell.Controls )
          {

          CheckBox checkBox = control as CheckBox;
          if (checkBox != null)
          {
          if (checkBox.Checked)
          {
          //retreive the value of tr.Cells[1]
          }
          }
          }

          }

          L Offline
          L Offline
          led mike
          wrote on last edited by
          #6

          michael_jhons wrote:

          the table is already populated its full of values

          Populated how? Dude, you have now posted THREE times and you still have NOT SPECIFIED what you are putting in those cells that you want to read from. Without that information we can't help you. I'm done with you now, good luck.

          led mike

          1 Reply Last reply
          0
          • M michael_jhons

            the table is already populated its full of values i want to retreive that value. here's the code:

            foreach(TableRow tr in TbTariffTb.Rows)
            {
            TableCell cell = tr.Cells[0];
            TableCell celCli=tr.Cells[1];

            foreach (Control control in cell.Controls )
            {

            CheckBox checkBox = control as CheckBox;
            if (checkBox != null)
            {
            if (checkBox.Checked)
            {
            //retreive the value of tr.Cells[1]
            }
            }
            }

            }

            H Offline
            H Offline
            Herman T Instance
            wrote on last edited by
            #7

            your on a good way but there is a slight detail. Your Code:

            foreach(TableRow tr in TbTariffTb.Rows){TableCell cell = tr.Cells[0];TableCell celCli=tr.Cells[1];foreach (Control control in cell.Controls ){						CheckBox checkBox = control as CheckBox;if (checkBox != null){ if (checkBox.Checked)  {    //retreive the value of tr.Cells[1]	
            }}}}
            

            My Advice

            foreach(TableRow tr in TbTariffTb.Rows)
            {
            	CheckBox checkBox = tr.FindControl("IDofYourCheckBox");
            	if (checkBox.Checked)
            	{
            		// Option 1: scan all Cells
            		foreach (TableCell cell in tr.Cells)
            		{	
            			String value = cell.Text;	
            		}
            
            		//Option 2: scan the wanted cell
            		String Value = tr.Cells[1].Text; // if not in edit mode
            		String Value2 = ((TextBox)tr.Cells[1].Controls[0]).Text; // if in Edit mode
            
            	}
            }
            
            H M 2 Replies Last reply
            0
            • H Herman T Instance

              your on a good way but there is a slight detail. Your Code:

              foreach(TableRow tr in TbTariffTb.Rows){TableCell cell = tr.Cells[0];TableCell celCli=tr.Cells[1];foreach (Control control in cell.Controls ){						CheckBox checkBox = control as CheckBox;if (checkBox != null){ if (checkBox.Checked)  {    //retreive the value of tr.Cells[1]	
              }}}}
              

              My Advice

              foreach(TableRow tr in TbTariffTb.Rows)
              {
              	CheckBox checkBox = tr.FindControl("IDofYourCheckBox");
              	if (checkBox.Checked)
              	{
              		// Option 1: scan all Cells
              		foreach (TableCell cell in tr.Cells)
              		{	
              			String value = cell.Text;	
              		}
              
              		//Option 2: scan the wanted cell
              		String Value = tr.Cells[1].Text; // if not in edit mode
              		String Value2 = ((TextBox)tr.Cells[1].Controls[0]).Text; // if in Edit mode
              
              	}
              }
              
              H Offline
              H Offline
              Herman T Instance
              wrote on last edited by
              #8

              ou might even have to cast: CheckBox checkBox = (CheckBox)tr.FindControl("IDofYourCheckBox");

              M 1 Reply Last reply
              0
              • H Herman T Instance

                ou might even have to cast: CheckBox checkBox = (CheckBox)tr.FindControl("IDofYourCheckBox");

                M Offline
                M Offline
                michael_jhons
                wrote on last edited by
                #9

                thank you a lot digimanus, i really apreciate your answer a lot thank you

                1 Reply Last reply
                0
                • H Herman T Instance

                  your on a good way but there is a slight detail. Your Code:

                  foreach(TableRow tr in TbTariffTb.Rows){TableCell cell = tr.Cells[0];TableCell celCli=tr.Cells[1];foreach (Control control in cell.Controls ){						CheckBox checkBox = control as CheckBox;if (checkBox != null){ if (checkBox.Checked)  {    //retreive the value of tr.Cells[1]	
                  }}}}
                  

                  My Advice

                  foreach(TableRow tr in TbTariffTb.Rows)
                  {
                  	CheckBox checkBox = tr.FindControl("IDofYourCheckBox");
                  	if (checkBox.Checked)
                  	{
                  		// Option 1: scan all Cells
                  		foreach (TableCell cell in tr.Cells)
                  		{	
                  			String value = cell.Text;	
                  		}
                  
                  		//Option 2: scan the wanted cell
                  		String Value = tr.Cells[1].Text; // if not in edit mode
                  		String Value2 = ((TextBox)tr.Cells[1].Controls[0]).Text; // if in Edit mode
                  
                  	}
                  }
                  
                  M Offline
                  M Offline
                  michael_jhons
                  wrote on last edited by
                  #10

                  digimanus i tried all methods u gave me, which i alresdy tried it before String Value2 = ((TextBox)tr.Cells[1].Controls[0]).Text; an error occured it gives me: specified cast is not valid, do you think textbox is the control which has to be specified for this cell ? thank you for your help

                  H 1 Reply Last reply
                  0
                  • M michael_jhons

                    digimanus i tried all methods u gave me, which i alresdy tried it before String Value2 = ((TextBox)tr.Cells[1].Controls[0]).Text; an error occured it gives me: specified cast is not valid, do you think textbox is the control which has to be specified for this cell ? thank you for your help

                    H Offline
                    H Offline
                    Herman T Instance
                    wrote on last edited by
                    #11

                    IS the row in Edit mode? (EditIndex > -1 in GridView) Than use the above code Else String Value2 = tr.Cells[1].Text; Otherwise. Set a breakpoint on the line with the (TextBox) cast. When reaching the breakpoint (Build = debug) add a watch on tr.Cells[1].Controls See how many controls the Count gives. If larger than 1 try in the watch all other controls in the array like tr.Cells[1].Controls[1] tr.Cells[1].Controls[2] tr.Cells[1].Controls[and so on] In that case you can see in which control your data exists. Have Fun

                    M 1 Reply Last reply
                    0
                    • H Herman T Instance

                      IS the row in Edit mode? (EditIndex > -1 in GridView) Than use the above code Else String Value2 = tr.Cells[1].Text; Otherwise. Set a breakpoint on the line with the (TextBox) cast. When reaching the breakpoint (Build = debug) add a watch on tr.Cells[1].Controls See how many controls the Count gives. If larger than 1 try in the watch all other controls in the array like tr.Cells[1].Controls[1] tr.Cells[1].Controls[2] tr.Cells[1].Controls[and so on] In that case you can see in which control your data exists. Have Fun

                      M Offline
                      M Offline
                      michael_jhons
                      wrote on last edited by
                      #12

                      it's alright i was populationg the cell by this method: tablecell.Controls.Add(new LiteralControl(SomeString)); when i used tablecell.Text=SomeString; it's working fine Thanks for the help

                      1 Reply Last reply
                      0
                      Reply
                      • Reply as topic
                      Log in to reply
                      • Oldest to Newest
                      • Newest to Oldest
                      • Most Votes


                      • Login

                      • Don't have an account? Register

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • World
                      • Users
                      • Groups