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
  1. Home
  2. Web Development
  3. ASP.NET
  4. Dynamic table Onclick

Dynamic table Onclick

Scheduled Pinned Locked Moved ASP.NET
helpquestion
7 Posts 3 Posters 2 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.
  • M Offline
    M Offline
    Morgs Morgan
    wrote on last edited by
    #1

    Hi guys, i am creating a table on runtime, i would like to add a few attributs to this table. I have so far managed to add:

    tr.Attributes.Add("onmouseover", "this.style.backgroundImage='url(images/pagebg.jpg)';this.style.cursor='pointer';");
    tr.Attributes.Add("onmouseout", "this.style.backgroundImage='url(images/tagcontent.gif)';this.style.cursor='pointer';");

    ..but i would also like to add an 'onclick' so that when a user clicks on a row then a radio button in that table on that row...does anyone know how i can do that? please help me... Regards, Morgs

    A R 2 Replies Last reply
    0
    • M Morgs Morgan

      Hi guys, i am creating a table on runtime, i would like to add a few attributs to this table. I have so far managed to add:

      tr.Attributes.Add("onmouseover", "this.style.backgroundImage='url(images/pagebg.jpg)';this.style.cursor='pointer';");
      tr.Attributes.Add("onmouseout", "this.style.backgroundImage='url(images/tagcontent.gif)';this.style.cursor='pointer';");

      ..but i would also like to add an 'onclick' so that when a user clicks on a row then a radio button in that table on that row...does anyone know how i can do that? please help me... Regards, Morgs

      A Offline
      A Offline
      Arun Jacob
      wrote on last edited by
      #2

      Have you tried adding onclick attribute just as you added other attributes? whats the problem you are facing?

      Arun Jacob My Technical Blog : Code.NET

      M 1 Reply Last reply
      0
      • A Arun Jacob

        Have you tried adding onclick attribute just as you added other attributes? whats the problem you are facing?

        Arun Jacob My Technical Blog : Code.NET

        M Offline
        M Offline
        Morgs Morgan
        wrote on last edited by
        #3

        Hi Arun...thanks for your reply, i don't know how to add an onclick so that a radio button gets checked.. here is the missing part:

        tr.Attributes.Add(key, value); //example
        tr.Attributes.Add("onclick", "?");//am not sure what add on the ? so that a radio button can get selected

        Please help me..

        A 1 Reply Last reply
        0
        • M Morgs Morgan

          Hi Arun...thanks for your reply, i don't know how to add an onclick so that a radio button gets checked.. here is the missing part:

          tr.Attributes.Add(key, value); //example
          tr.Attributes.Add("onclick", "?");//am not sure what add on the ? so that a radio button can get selected

          Please help me..

          A Offline
          A Offline
          Arun Jacob
          wrote on last edited by
          #4

          MorgSim wrote:

          tr.Attributes.Add("onclick", "?");

          Call javascript function,

          tr.Attributes.Add("onclick", "SelectRadioButton('"+ radiobutton.ClientID +"');");

          and from that javascriptmethod select the radio button,

          function SelectRadioButton(rbtnId)
          {
          document.getElementById(rbtnId).checked = !document.getElementById(rbtnId).checked;
          }

          Code is not tested, but I hope this will work.

          Arun Jacob My Technical Blog : Code.NET

          M 1 Reply Last reply
          0
          • M Morgs Morgan

            Hi guys, i am creating a table on runtime, i would like to add a few attributs to this table. I have so far managed to add:

            tr.Attributes.Add("onmouseover", "this.style.backgroundImage='url(images/pagebg.jpg)';this.style.cursor='pointer';");
            tr.Attributes.Add("onmouseout", "this.style.backgroundImage='url(images/tagcontent.gif)';this.style.cursor='pointer';");

            ..but i would also like to add an 'onclick' so that when a user clicks on a row then a radio button in that table on that row...does anyone know how i can do that? please help me... Regards, Morgs

            R Offline
            R Offline
            raju melveetilpurayil
            wrote on last edited by
            #5

            try like this.

            protected void Button1_Click(object sender, EventArgs e)
            {
            HtmlTable table = new HtmlTable();
            HtmlTableRow tr;
            HtmlTableCell td;
            //adding 10 rows
            for(int i=0;i<10;i++)
            {
            tr = new HtmlTableRow();
            //adding id for table row
            tr.ID = "tr" + i.ToString();
            //adding columns
            string cbxID = string.Empty;
            for (int cols = 0; cols < 2; cols++)
            {
            td = new HtmlTableCell();
            if (cols == 0)
            {
            HtmlInputRadioButton radio = new HtmlInputRadioButton();
            //adding radiobutton ID
            cbxID = "rdb" + i.ToString();
            radio.ID = cbxID;
            //different groupname.
            radio.Name = i.ToString();
            radio.Value = "RadioButton" + i.ToString();
            //adding Radio Buttton to Table cell
            td.Controls.Add(radio);
            //adding table cell to table Row
            tr.Controls.Add(td);
            }
            else
            {
            //add table cell text
            td.InnerText = "Row Number" + i.ToString();
            //adding script
            td.Attributes.Add("onclick", string.Format("checkRadio('{0}');", cbxID));
            //adding style
            td.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
            tr.Controls.Add(td);

                        }
                    }
                    table.Controls.Add(tr);
                }
                Panel1.Controls.Add(table);
            }
            

            <div>
            <asp:Button ID="Button1" runat="server" Text="create Table"
            onclick="Button1_Click" />
            <asp:Panel ID="Panel1" runat="server">
            </asp:Panel>
            <script language="javascript">
            //script only to ckeck radio button
            function checkRadio(cbx)
            {
            document.getElementById(cbx).checked = true;
            }
            </script>
            </div>

            [edit] add comments[/edit]

            modified on Monday, August 16, 2010 6:46 AM

            M 1 Reply Last reply
            0
            • R raju melveetilpurayil

              try like this.

              protected void Button1_Click(object sender, EventArgs e)
              {
              HtmlTable table = new HtmlTable();
              HtmlTableRow tr;
              HtmlTableCell td;
              //adding 10 rows
              for(int i=0;i<10;i++)
              {
              tr = new HtmlTableRow();
              //adding id for table row
              tr.ID = "tr" + i.ToString();
              //adding columns
              string cbxID = string.Empty;
              for (int cols = 0; cols < 2; cols++)
              {
              td = new HtmlTableCell();
              if (cols == 0)
              {
              HtmlInputRadioButton radio = new HtmlInputRadioButton();
              //adding radiobutton ID
              cbxID = "rdb" + i.ToString();
              radio.ID = cbxID;
              //different groupname.
              radio.Name = i.ToString();
              radio.Value = "RadioButton" + i.ToString();
              //adding Radio Buttton to Table cell
              td.Controls.Add(radio);
              //adding table cell to table Row
              tr.Controls.Add(td);
              }
              else
              {
              //add table cell text
              td.InnerText = "Row Number" + i.ToString();
              //adding script
              td.Attributes.Add("onclick", string.Format("checkRadio('{0}');", cbxID));
              //adding style
              td.Style.Add(HtmlTextWriterStyle.Cursor, "pointer");
              tr.Controls.Add(td);

                          }
                      }
                      table.Controls.Add(tr);
                  }
                  Panel1.Controls.Add(table);
              }
              

              <div>
              <asp:Button ID="Button1" runat="server" Text="create Table"
              onclick="Button1_Click" />
              <asp:Panel ID="Panel1" runat="server">
              </asp:Panel>
              <script language="javascript">
              //script only to ckeck radio button
              function checkRadio(cbx)
              {
              document.getElementById(cbx).checked = true;
              }
              </script>
              </div>

              [edit] add comments[/edit]

              modified on Monday, August 16, 2010 6:46 AM

              M Offline
              M Offline
              Morgs Morgan
              wrote on last edited by
              #6

              Yeah thanks alot man...it worked just fine.. THANKYOU

              1 Reply Last reply
              0
              • A Arun Jacob

                MorgSim wrote:

                tr.Attributes.Add("onclick", "?");

                Call javascript function,

                tr.Attributes.Add("onclick", "SelectRadioButton('"+ radiobutton.ClientID +"');");

                and from that javascriptmethod select the radio button,

                function SelectRadioButton(rbtnId)
                {
                document.getElementById(rbtnId).checked = !document.getElementById(rbtnId).checked;
                }

                Code is not tested, but I hope this will work.

                Arun Jacob My Technical Blog : Code.NET

                M Offline
                M Offline
                Morgs Morgan
                wrote on last edited by
                #7

                Yeahh thanks Alot Arun...worked just fine.. ;)

                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