質問

Here is my Javascript I am currently using to select the Monitor selected value to be displayed in my popup :

        var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
        var strUser = theMonitor.options[theMonitor.selectedIndex].text;

This is the actual Dropdownlist code :

<tr>
            <td nowrap="nowrap" style="width:132px">
                Monitor?</td>
            <td nowrap="nowrap" style="width:464px">
                <asp:DropDownList ID="MonitorInductionDDL" runat="server" Height="25px"
                    Width="334px" >
                    <asp:ListItem Selected="True" Value="0">Yes</asp:ListItem>
                    <asp:ListItem Value="1">No</asp:ListItem>
                </asp:DropDownList>
                </td>
        </tr>

And this is my VB.NET code to assign the values of this to be displayed ( well that's what it's ment to do i think ) :

Dim Upload As Button
        Upload = e.Row.FindControl("UpdateInduction")
        Cell1 = e.Row.DataItem("Description").ToString
        Cell2 = e.Row.DataItem("Id").ToString
        Cell3 = e.Row.DataItem("Monitor").ToString
        Upload.OnClientClick = String.Format("Javascript:ShowPopup('uploadPopup', '{0}', '{1}', '{2}');", Cell1, Cell2, Cell3)

Here is a picture of the popup:

enter image description here

As you may notice I have clicked the Update Button in the background to trigger this popup from the update button located on the 'Resignation' row where the monitor is 'No' yet this displays as yes ...

so my question is , how would I be able to have the Dropdownlist in the popup Monitor become the value of whatever is in that column?

I honestly don't know where I'm going wrong here so fast help and guidance would be nice , thank you in advance.

役に立ちましたか?

解決

I think the error is on the second line, you are getting the value from the selected text of the ddl. but you have to set the value for it, like the following.

instead of

var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
    var strUser = theMonitor.options[theMonitor.selectedIndex].text;

put the below code

function showpopup(str1,str2,str3)
{
var theMonitor = document.getElementById("ctl00_ContentPlaceHolder1_MonitorInductionDDL");
    theMonitor.options[theMonitor.selectedIndex].text= str3;
}

他のヒント

Add JavaScript debugger break-point to check what value you are getting after clicking on the grid. If you are getting 'No' and still not able to set the selected text/value of the drop down to 'No', make sure there is no leading/trailing space.

I faced such a scenario.

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