Link to home
Start Free TrialLog in
Avatar of IntercareSupport
IntercareSupport

asked on

Template field dropdown errors in detailsview

I am trying to convert a bound field to a  template field.  I want to have a dropdown list where users can use during "Update" mode.  Basically, I'm trying to do what this guy is doing: http://blogs.msdn.com/robburke/archive/2005/04/01/404727.aspx

The error I'm getting is this:

'DropDownList3' has a SelectedValue which is invalid because it does not exist in the list of items.
Parameter name: value

Any ideas?
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
                                DataSourceID="qry_Enrollment" Height="50px" Width="551px">
                                <Fields>
                                    <asp:BoundField DataField="Enroll_Date" HeaderText="Enroll Date" ReadOnly="True"
                                        SortExpression="Enroll_Date" />
                                    <asp:BoundField DataField="Provider_Assessed" HeaderText="Provider Assessed Date" SortExpression="Provider_Assessed" />
                                    <asp:BoundField DataField="GAIC_Enrollment" HeaderText="GAIC Enrollment" SortExpression="GAIC_Enrollment" />
                                    <asp:BoundField DataField="GA_Other_Enrollment" HeaderText="GA Other Enrollment"
                                        SortExpression="GA_Other_Enrollment" />
                                    <asp:BoundField DataField="Current_Status" HeaderText="Current Status" SortExpression="Current_Status" />
                                    <asp:BoundField DataField="Due_Date" HeaderText="Due Date" ReadOnly="True" SortExpression="Due_Date" />
                                    <asp:BoundField DataField="Pregnancy_Amt" HeaderText="Gravida" SortExpression="Pregnancy_Amt" />
                                    <asp:BoundField DataField="Birth_Amt" HeaderText="Para" SortExpression="Birth_Amt" />
                                    <asp:TemplateField HeaderText="Hospital" SortExpression="Hospital">
                                        <EditItemTemplate>
                                            <asp:DropDownList DataTextField="Hospital" DataValueField="Hospital" ID="DropDownList3" Runat="server" SelectedValue='<%# Bind("Hospital") %>' >
                                                  <asp:ListItem>Lakeland</asp:ListItem>
                                                  <asp:ListItem>Other</asp:ListItem>
                                                  <asp:ListItem>UT</asp:ListItem>
                                                  <asp:ListItem>MD</asp:ListItem>
                                            </asp:DropDownList>
                                        </EditItemTemplate>
                                        <InsertItemTemplate>
                                        </InsertItemTemplate>
                                        <ItemTemplate>
                                            <asp:Label ID="Label1" runat="server" Text='<%# Bind("Hospital") %>'></asp:Label>
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:CheckBoxField DataField="HIPPA" HeaderText="HIPPA" SortExpression="HIPPA" />
                                    <asp:CommandField ShowEditButton="True" />
                                </Fields>
                                <RowStyle BackColor="White" BorderColor="Gainsboro" Font-Size="Smaller" ForeColor="Black" />
                                <FieldHeaderStyle Font-Bold="True" />
                            </asp:DetailsView>

Open in new window

Avatar of expertsoul
expertsoul
Flag of United States of America image

Are you trying to specify SelectedValue from codebehind?
Avatar of IntercareSupport
IntercareSupport

ASKER

No, I'm trying to display a drop down list so I can have the values hard coded instead of relying on the users to enter the data right.
So in the ItemCommand event handler you're getting this error?

If so, try this:

dim ddl as DropDownList = e.Item.FindControl("DropDownList3")

dim ddlValue as string = ddl.SelectedValue

Apologies, I missed you were using a DetailsView

try this:

dim ddl as DropDownList = e.FindControl("DropDownList3")
dim ddlValue as string = ddl.SelectedValue
Where do I put this code?  I'm new to ASP.net.
You would put it in the ItemCommand event handler for your DetailsView (in the codebehind) something like this:

Private Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
  dim ddl as DropDownList = e.FindControl("DropDownList3")
  dim ddlValue as string = ddl.SelectedValue
End Sub
BC30456: 'FindControl' is not a member of 'System.Web.UI.WebControls.DetailsViewCommandEventArgs'.
ah, very sorry... must be half asleep today.

Try this:
Private Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
  dim ddl as DropDownList = DetailsView1.FindControl("DropDownList3")
  dim ddlValue as string = ddl.SelectedValue
End Sub

Open in new window

It occurred to me that you weren't having trouble finding the control, but that you were trying to verify if a value was in the dropdownlist...

If that's the case, can you post the code that generated the error?
Here you go.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="C#" %>
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ICHN MIHP/Maternal Log</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
 
 
<body>
    <form id="form1" runat="server">
    <div id="container">
	    <div id="header">
		    <h1>
            
                Maternal Log
        </h1>
		<p>
            InterCare Community Health Network</p>
	</div>
	<div id="nav">
		<ul>
			<li><a href="http://www.spyka.net/codes" title="help">help</a></li>
			<li><a href="add_pt.aspx" title="edit patient">edit patient</a></li>
			<li><a href="add_pt.aspx" title="add patient">add patient</a></li>
			<li><a href="http://kenobi:81/index.aspx" class="selected" title="home">home</a></li>
        </ul>
	</div>
	<div id="content">
		<div id="page" style="text-align: center">
            <p>
                &nbsp;</p>
            Add a patient to the Maternal Log.<br />
            <br />
            Find the patient you wish to add, then click "add".<p style="text-align: center">
                &nbsp;</p>
            <p style="text-align: center">
 
                    <tr>
                        <td style="height: 26px">
                            Last Name</td>
                        &nbsp; &nbsp;
                        <td style="height: 26px">
                            <asp:TextBox ID="txt_Last_Name" runat="server"></asp:TextBox></td>
                        <td style="height: 26px">
                        </td>
                    </tr>
            </p>
            <p style="text-align: center">
                First Name &nbsp; &nbsp;
                <asp:TextBox ID="txt_first_name" runat="server"></asp:TextBox></p>
            <p>
                Chart Number
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
            <p style="text-align: center">
 
                <asp:Button ID="Button1" runat="server" Text="Submit" />
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataKeyNames="Patient_Id" DataSourceID="Client_Summary">
                    <Columns>
                        <asp:BoundField DataField="Patient_Last_Name" HeaderText="Patient_Last_Name" SortExpression="Patient_Last_Name" />
                        <asp:BoundField DataField="Patient_First_Name" HeaderText="Patient_First_Name" SortExpression="Patient_First_Name" />
                        <asp:BoundField DataField="Patient_Chart" HeaderText="Patient_Chart" SortExpression="Patient_Chart" />
                        <asp:BoundField DataField="Patient_DOB" HeaderText="Patient_DOB" SortExpression="Patient_DOB" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="Client_Summary" runat="server" ConnectionString="<%$ ConnectionStrings:Chorus_Reporting_Guest_User %>"
                    SelectCommand="SELECT Patient_Last_Name, Patient_First_Name, Patient_Chart, Patient_Id, Patient_DOB FROM Patient_Personal WHERE (@Patient_First_Name IS NULL OR Patient_First_Name LIKE '%' + @Patient_First_Name + '%') AND (@Patient_Last_Name IS NULL OR Patient_Last_Name LIKE '%' + @Patient_Last_Name + '%') AND (@Patient_Chart IS NULL OR Patient_Chart LIKE '%' + @Patient_Chart + '%')">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="txt_first_name" Name="Patient_First_Name" PropertyName="Text" />
                        <asp:ControlParameter ControlID="txt_Last_Name" Name="Patient_Last_Name" PropertyName="Text" />
                        <asp:ControlParameter ControlID="TextBox1" Name="Patient_Chart" PropertyName="Text" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </p>
            <p>
                            <BUTTON TYPE=BUTTON
                            ONCLICK="window.history.back();"
                            class=btnParms name=btnContinue ID="Button2" style="text-align: center">Previous Page</BUTTON>
                
		</div>
		<div class="clear"></div>
	</div>
	<div id="footer">
		<p>
            2009 InterCare Community Health Network</p>
	</div>
			
</div>
	</form>
</body>
</html>

Open in new window

Wait, here's the version with your code.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="VB" %>
 
<script runat="server">
 
Private Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
  dim ddl as DropDownList = DetailsView1.FindControl("DropDownList3")
  dim ddlValue as string = ddl.SelectedValue
End Sub
</script>
 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ICHN MIHP/Maternal Log</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
 
 
<body>
    <form id="form1" runat="server">
    <div id="container">
	    <div id="header">
		    <h1>
            
                Maternal Log
        </h1>
		<p>
            InterCare Community Health Network</p>
	</div>
	<div id="nav">
		<ul>
			<li><a href="http://www.spyka.net/codes" title="help">help</a></li>
			<li><a href="add_pt.aspx" title="edit patient">edit patient</a></li>
			<li><a href="add_pt.aspx" title="add patient">add patient</a></li>
			<li><a href="http://kenobi:81/index.aspx" class="selected" title="home">home</a></li>
        </ul>
	</div>
	<div id="content">
		<div id="page" style="text-align: center">
            <p>
                &nbsp;</p>
            Add a patient to the Maternal Log.<br />
            <br />
            Find the patient you wish to add, then click "add".<p style="text-align: center">
                &nbsp;</p>
            <p style="text-align: center">
 
                    <tr>
                        <td style="height: 26px">
                            Last Name</td>
                        &nbsp; &nbsp;
                        <td style="height: 26px">
                            <asp:TextBox ID="txt_Last_Name" runat="server"></asp:TextBox></td>
                        <td style="height: 26px">
                        </td>
                    </tr>
            </p>
            <p style="text-align: center">
                First Name &nbsp; &nbsp;
                <asp:TextBox ID="txt_first_name" runat="server"></asp:TextBox></p>
            <p>
                Chart Number
                <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox></p>
            <p style="text-align: center">
 
                <asp:Button ID="Button1" runat="server" Text="Submit" />
                <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                    AutoGenerateColumns="False" DataKeyNames="Patient_Id" DataSourceID="Client_Summary" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                    <Columns>
                        <asp:BoundField DataField="Patient_Last_Name" HeaderText="Patient_Last_Name" SortExpression="Patient_Last_Name" />
                        <asp:BoundField DataField="Patient_First_Name" HeaderText="Patient_First_Name" SortExpression="Patient_First_Name" />
                        <asp:BoundField DataField="Patient_Chart" HeaderText="Patient_Chart" SortExpression="Patient_Chart" />
                        <asp:BoundField DataField="Patient_DOB" HeaderText="Patient_DOB" SortExpression="Patient_DOB" />
                    </Columns>
                </asp:GridView>
                <asp:SqlDataSource ID="Client_Summary" runat="server" ConnectionString="<%$ ConnectionStrings:Chorus_Reporting_Guest_User %>"
                    SelectCommand="SELECT Patient_Last_Name, Patient_First_Name, Patient_Chart, Patient_Id, Patient_DOB FROM Patient_Personal WHERE (@Patient_First_Name IS NULL OR Patient_First_Name LIKE '%' + @Patient_First_Name + '%') AND (@Patient_Last_Name IS NULL OR Patient_Last_Name LIKE '%' + @Patient_Last_Name + '%') AND (@Patient_Chart IS NULL OR Patient_Chart LIKE '%' + @Patient_Chart + '%')">
                    <SelectParameters>
                        <asp:ControlParameter ControlID="txt_first_name" Name="Patient_First_Name" PropertyName="Text" />
                        <asp:ControlParameter ControlID="txt_Last_Name" Name="Patient_Last_Name" PropertyName="Text" />
                        <asp:ControlParameter ControlID="TextBox1" Name="Patient_Chart" PropertyName="Text" />
                    </SelectParameters>
                </asp:SqlDataSource>
            </p>
            <p>
                            <BUTTON TYPE=BUTTON
                            ONCLICK="window.history.back();"
                            class=btnParms name=btnContinue ID="Button2" style="text-align: center">Previous Page</BUTTON>
                
		</div>
		<div class="clear"></div>
	</div>
	<div id="footer">
		<p>
            2009 InterCare Community Health Network</p>
	</div>
			
</div>
	</form>
</body>
</html>

Open in new window

Did you change from a DetailsView to a GridView? How many records are you updating (at a time)?
I'm so sorry!  I posted the wrong code.  I'm doing several things at once, and apparently I'm not doing so well.  Below is the complete code, plus your code.  The error I'm getting is now this:

Compiler Error Message: BC30456: 'DetailsView1_PageIndexChanging' is not a member of 'ASP.maternal_enrollment_aspx'.

I'm lost.  I just want a dropdown instead of a textbox.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<%@ Page Language="VB" %>
 
<script runat="server">
 
    Private Sub DetailsView1_ItemCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.DetailsViewCommandEventArgs) Handles DetailsView1.ItemCommand
        Dim ddl As DropDownList = DetailsView1.FindControl("DropDownList3")
        Dim ddlValue As String = ddl.SelectedValue
    End Sub
 
</script>
 
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>ICHN MIHP/Maternal Log</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
 
 
</head>
 
 
<html xmlns="http://www.w3.org/1999/xhtml">
<body>
    <form id="form1" runat="server">
    <div id="container">
	    <div id="header">
		    <h1>
            
                Maternal Log
        </h1>
		<p>
            InterCare Community Health Network</p>
	</div>
	<div id="nav">
		<ul>
			<li><a href="http://kenobi:81/index.aspx" title="help">help</a></li>
			<li><a href="http://www.spyka.net/web-templates" title="edit patient">edit patient</a></li>
			<li><a href="http://www.spyka.net/scripts" title="add patient">add patient</a></li>			<li><a href="#" class="selected" title="home">home</a></li>
        </ul>
	</div>
	<div id="content" style="text-align: right">
		<div id="page" style="text-align: left">
            <p style="text-align: left" id="P1" runat="server">
                </p>
            <p>
                <table style="width: 100%; height: 100%">
                    <tr>
                        <td style="width: 100px; height: 288px;">
                            &nbsp;<span style="font-size: 14pt">Enrollment Details<br />
                                <br />
                                <asp:DetailsView ID="DetailsView1"
                                    runat="server" AutoGenerateRows="False" DataSourceID="qry_Enrollment" Height="50px"
                                    Width="519px" OnPageIndexChanging="DetailsView1_PageIndexChanging">
                                    <RowStyle Font-Size="Smaller" />
                                    <Fields>
                                    <asp:BoundField DataField="Enroll_Date" HeaderText="Enroll Date" ReadOnly="True"
                                        SortExpression="Enroll_Date" />
                                    <asp:BoundField DataField="Provider_Assessed" HeaderText="Provider Assessed Date" SortExpression="Provider_Assessed" />
                                    <asp:BoundField DataField="GAIC_Enrollment" HeaderText="GAIC Enrollment" SortExpression="GAIC_Enrollment" />
                                    <asp:BoundField DataField="GA_Other_Enrollment" HeaderText="GA Other Enrollment"
                                        SortExpression="GA_Other_Enrollment" />
                                    <asp:BoundField DataField="Current_Status" HeaderText="Current Status" SortExpression="Current_Status" />
                                    <asp:BoundField DataField="Due_Date" HeaderText="Due Date" ReadOnly="True" SortExpression="Due_Date" />
                                    <asp:BoundField DataField="Pregnancy_Amt" HeaderText="Gravida" SortExpression="Pregnancy_Amt" />
                                    <asp:BoundField DataField="Birth_Amt" HeaderText="Para" SortExpression="Birth_Amt" />
                                        <asp:TemplateField HeaderText="Hospital" SortExpression="Hospital">
                                            <EditItemTemplate>
                                             <asp:DropDownList DataTextField="Hospital" DataValueField="Hospital" ID="DropDownList3" Runat="server" SelectedValue='<%# Bind("Hospital") %>' >
                                                  <asp:ListItem>Lakeland</asp:ListItem>
                                                  <asp:ListItem>Other</asp:ListItem>
                                                  <asp:ListItem>UT</asp:ListItem>
                                                  <asp:ListItem>MD</asp:ListItem>
                                            </asp:DropDownList>
                                            </EditItemTemplate>
                                            <InsertItemTemplate>
                                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("Hospital") %>'></asp:TextBox>
                                            </InsertItemTemplate>
                                            <ItemTemplate>
                                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("Hospital") %>'></asp:Label>
                                            </ItemTemplate>
                                        </asp:TemplateField>
                                   <asp:CheckBoxField DataField="HIPPA" HeaderText="HIPPA" SortExpression="HIPPA" />
                                    <asp:CommandField ShowEditButton="True" />
                                    </Fields>
                                </asp:DetailsView>
                                <br />
                            </span>
                            <br />
                            &nbsp;<br />
                            <asp:SqlDataSource id="qry_Enrollment" runat="server" ConnectionString="<%$ ConnectionStrings:MIHP_MaternalConnectionString %>" SelectCommand="SELECT CONVERT (VARCHAR(8), [Enroll Date], 1) AS Enroll_Date, [GAIC Enrollment] AS GAIC_Enrollment, [GA Other Enrollment] AS GA_Other_Enrollment, [Current Status] AS Current_Status, CONVERT (VARCHAR(8), [Due Date], 1) AS Due_Date, [Pregnancy Amt] AS Pregnancy_Amt, [Birth Amt] AS Birth_Amt, Hospital, HIPPA, Patient_ID, Provider_Assessed FROM Detail WHERE (Patient_ID = @Patient_Id)" UpdateCommand="UPDATE Detail SET [Current Status] = @Current_Status">
                                <SelectParameters>
                                    <asp:QueryStringParameter Name="Patient_Id" QueryStringField="Patient_Id" />
                                </SelectParameters>
                                <UpdateParameters>
                                    <asp:Parameter Name="Current_Status" />
                                </UpdateParameters>
                            </asp:SqlDataSource>
 
<BUTTON TYPE=BUTTON
                            ONCLICK="window.history.back();"
                            class=btnParms name=btnContinue ID="Button2" style="text-align: center">Previous Page</BUTTON>                 </tr>
                </table>
            </p>
                
                
		</div>
		<div class="clear"></div>
	</div>
	<div id="footer">
		<p>
            2009 InterCare Community Health Network</p>
	</div>
			
</div>
	</form>
</body>
</html>

Open in new window

I've got to run. If anyone else is reading along and lend a hand this evening, please jump in.

I will leave you with a link to an article on retrieving the value of a DDL within a DataGrid. Your code will be a bit diff., but hopefully you'll see the general idea and be able to apply the concept:

http://www.codeproject.com/KB/aspnet/GridviewItemDropdown.aspx 

I'll check in a bit later and see if this is still open.
ASKER CERTIFIED SOLUTION
Avatar of IntercareSupport
IntercareSupport

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial