Dynamic table Onclick
-
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
-
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
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
-
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
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 selectedPlease help me..
-
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 selectedPlease help me..
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
-
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
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
-
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
Yeah thanks alot man...it worked just fine.. THANKYOU
-
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
Yeahh thanks Alot Arun...worked just fine.. ;)