Click here to Skip to main content
15,896,320 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created new dropdown from asp.net code behind and want to change name of dropdown (selectbox)..how to change

for exp.

<select id="ctl00_ContentPlaceHolder1_perage[1]" name="ctl00$ContentPlaceHolder1$perage[1]"></select>

i want to make name as

name="ageperwise[]"
Posted

1 solution

It very simple with the help of Jquery


value="change" />


here i have two button named read or changed and a textbox.
read button is simply reading the attribute value and the change button is changing the value of attribute.


here is the Jquery code



$(function () {

$("#Button5").click(function () {
alert($("#Text1").attr("name"));
});

$("#Button6").click(function () {
$("#Text1").attr("name", "Singh");
});
})
 
Share this answer
 
Comments
maulikshah1990 19-Nov-13 1:30am    
Ok..thanks..but i have other question

I have manually added

chddiv_1.InnerHtml="<select id=\"ctl00_ContentPlaceHolder1_perage["+pcnt+"]\" name=\"ageperwise["+pcnt+"]\">"+
"<option value=\"<1\"><1</option>" +
"<option value=\"1\">1</option>" +
"<option value=\"2\">2</option>" +
"<option value=\"3\">3</option>" +
"<option value=\"4\">4</option>" +
"<option value=\"5\">5</option>" +
"<option value=\"6\">6</option>" +
"<option value=\"7\">7</option>" +
"<option value=\"8\">8</option>" +
"<option value=\"9\">9</option>" +
"<option value=\"10\">10</option>" +
"<option value=\"11\">11</option>" +
"<option value=\"12\">12</option>" +
"</select>";

then if i search for

DropDownList div2 = (DropDownList)Master.FindControl("ContentPlaceHolder1").FindControl("perage" + pcnt).FindControl("perage[" + pcnt + "]");

i get div2 as null..

i should get dropdown list

pls advice
Er Daljeet Singh 19-Nov-13 1:44am    
try by changing the name of the dropdown list..

DropDownList div2 = (DropDownList)Master.FindControl("ctl00_ContentPlaceHolder1_perage['"+pcnt+"']");

i think this will work fine..
maulikshah1990 19-Nov-13 1:47am    
Hi,,thanks but that doesnt work
Er Daljeet Singh 19-Nov-13 2:02am    
tell me one thing you are creating dropdownlist through code mean from code behind.
maulikshah1990 19-Nov-13 2:09am    
yes..i have uploaded code...
chddiv_1.InnerHtml="<select id=\"ctl00_ContentPlaceHolder1_perage["+pcnt+"]\" name=\"ageperwise["+pcnt+"]\">"+
"<option value=\"<1\"><1</option>" +
"<option value=\"1\">1</option>" +
"<option value=\"2\">2</option>" +
"<option value=\"3\">3</option>" +
"<option value=\"4\">4</option>" +
"<option value=\"5\">5</option>" +
"<option value=\"6\">6</option>" +
"<option value=\"7\">7</option>" +
"<option value=\"8\">8</option>" +
"<option value=\"9\">9</option>" +
"<option value=\"10\">10</option>" +
"<option value=\"11\">11</option>" +
"<option value=\"12\">12</option>" +
"</select>";


then if i search for

DropDownList div2 = (DropDownList)Master.FindControl("ContentPlaceHolder1").FindControl("perage[" + pcnt + "]");

i get div2 as null..

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900