How to check whether the id of RadGrid EditColumn is valid or not in Javascript

StackOverflow https://stackoverflow.com/questions/23669929

  •  23-07-2023
  •  | 
  •  

質問

I am using the following code in asp(code is written in javascript)

function Check_Option_IntRate() 
{
   debugger;

   for (var i=100; i<=110; i++)
   {
       var temp1='ctl00_MainContent_radgrd_InvPur_ctl00_ct'+i+'_rdo_intrev';

       if (document.getElementById(temp1))
       {
           var Rd_IntId= document.getElementById('temp1').id;
           if (document.getElementById('temp1').checked == true) {
              document.getElementById('call5').style.display = "Block";
              document.getElementById('call6').style.display = "Block";
       }
       else {
            document.getElementById('call5').style.display = "None";
            document.getElementById('call6').style.display = "None";
       }
   }
}
return false;

here rdo_intrev is radio button. used as asp control. This is being declared as a editcolum in RadGrid. So in every row of the radgrid the asp generatted id will change. Thats why i have used for loop here(ctl00_MainContent_radgrd_InvPur_ctl00_ct'+i+'_rdo_intrev). I want to check whether the control id is valid or not. But if (document.getElementById(temp1)) results null only.

How can i check that. Is there any better way to solve this problem.

Please help me. Thanks in advance.

役に立ちましたか?

解決

you can use the following code

  if (temp1)
           {
             var first=temp1+"_0";
            if (first.checked == true) {
                  document.getElementById('call5').style.display = "Block";
                  document.getElementById('call6').style.display = "Block";
           }
           else {
                document.getElementById('call5').style.display = "None";
                document.getElementById('call6').style.display = "None";
           }

Hope this will work.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top