?
Solved

accessing <asp:TemplateField <EditItemTemplate><asp:DropDownList via javascript

Posted on 2006-03-29
2
Medium Priority
?
1,238 Views
Last Modified: 2011-08-18
have a detailsview with a template field with a dropdown list.

I have attached a javascript function with:
foreach (DetailsViewRow dvr in dvEditPD.Rows)
        {
            ((DropDownList)dvr.FindControl("ddlSource")).Attributes.Add("onchange", "OtherSource()");
        }

and this fires...tested with a simple alert.

not sure if I should post this in the javascript forums...but....anyways.

in regular html aspx page I used the following to show/hide a text box based on selected value of ddlSource

{
var i=document.forms[0].elements['ddlSource'].selectedIndex
if (i==9) {
    document.getElementById('otherTextDiv').style.display = '';
    }
    else
    {
    document.getElementById('otherTextDiv').style.display = 'none';
    }
}

<td style="height: 25px">
   <div id="otherTextDiv" runat="server" style="DISPLAY: none" >
      <asp:TextBox id="txtOtherSource" runat="server">Plese Specify</asp:TextBox>
   </div>
</td>

now that I'm using a details view I can't figure out how to get into the templatefield to hide/show the div

                <asp:TemplateField>
                    <ItemTemplate>
                        <div id="otherTextDiv" runat="server" style="DISPLAY: none">
                            <asp:TextBox id="txtOtherSource" runat="server">Plese Specify</asp:TextBox>
                        </div>
                    </ItemTemplate>
                </asp:TemplateField>

basically I need to show/hide a text box if selection is 'Other' but need to do it client side, no postback.

if I need to move this to javascript, let me know.

high points, cause kind of urgent

thanx,
0
Comment
Question by:heincpa
2 Comments
 
LVL 8

Accepted Solution

by:
mppeters earned 2000 total points
ID: 16327022
You should pass in the client-side ID of the control to your javascript function.

foreach (DetailsViewRow dvr in dvEditPD.Rows)
        {
          DropDownList ddl =  ((DropDownList)dvr.FindControl("ddlSource"))
          ddl.Attributes.Add("onchange", "OtherSource('" + ddl.ClientID + "')");
        }

Then use that to find the control in javascript:

function OtherSource(clientId) {
var i=document.forms[0].elements[clientId].selectedIndex

Either that, or use the keyword 'this' to pass in an already instantiated instance of the control in javascript.
0
 
LVL 1

Author Comment

by:heincpa
ID: 16327865
I was so close...thanx for setting it straight!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question