Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I added another select or dropdown

Status
Not open for further replies.

wudang26

Technical User
May 18, 2012
7
US
I added another select or dropdown to my datagrid. Since Im doing this and im using getElementByTagName. I get errors since I have 2 dropdowns in my grid. So im trying to toggle the dropdown to display then hide.


function OnChange(down)
{
var flag = true;

var dropdowns = new Array(); //Create array to hold all the dropdown lists.
// var credit = new Arry();

var gridview = document.getElementById('<%=myDataGrid.ClientID %>'); //GridView1 is the id of ur gridview.

dropdowns = gridview.getElementsByTagName('select'); //Get all dropdown lists contained in GridView1.

for (var i = 0; i < dropdowns.length; i++)
{

if (dropdowns.item(i).value == '2') //If dropdown has no selected value
{
// down.parentElement.nextSibling.children[9].style.display = dis;
var txtshow = new Array();
txtshow = gridview.getElementsByTagName('input');
txtshow.item(i).style.display = 'block';
flag = false;
}

else
{

var txtshow = new Array();
txtshow = gridview.getElementsByTagName('input');
txtshow.item(i).style.display = 'none';
}

if (dropdowns.item(i).value == '1')
{
var txtDrop = new Array();
txtDrop = gridview.getElementsByTagName('label');
txtDrop.item(i).style.display = 'block';
}
else
{
var txtDrop = new Array();
txtDrop = gridview.getElementsByTagName('label');
txtDrop.item(i).style.display = 'none';
}

if (dropdowns.item(i).value == '3') -ERROR STARTS HERE
{
var txtOption = new Array();
txtOption = gridview.getElementsByTagName('select');
txtOption.item(i).style.display = 'block';
}
else
{
var txtOption = new Array();
txtOption = gridview.getElementsByTagName('select');
txtOption.item(i).style.display = 'none';
}


}
return flag;
}
//-->
</script>

<asp:DropDownList ID="DropDownList1" runat="server" onchange="javascript:OnChange(this);" Enabled="True">
<asp:ListItem Value ="0" >Select an Action</asp:ListItem>
<asp:ListItem Value ="1" >Drop</asp:ListItem>
<asp:ListItem Value ="2" >Change</asp:ListItem>
<asp:ListItem Value ="3" >Option</asp:ListItem>
</asp:DropDownList>
</ItemTemplate></asp:TemplateColumn>


This is in another column in the datagrid. This is the dropdown I want to toggle display.

<asp:TemplateColumn HeaderText="Option" Visible="true">

<ItemTemplate>
<select id="Select1" name="option">
<option>U</option>
<option>R</option>
<option>P</option>
<option>S</option> </select>
</ItemTemplate>
</asp:TemplateColumn>
 
And the errors are???

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
There's no error. It does not work correctly. It gets the wrong select in the datagrid and makes it invisible since Im using "getElementTagName". Not sure how to fix this.
 
Give the element you want to target a unique ID.

And: Seeing REAL HTML code would be more use than unrendered .NET code is.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.
Webmaster Forum
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top