Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 14:06:55
|
I have a dropdownlist inside the editable gridviewMy dropdownlist comes from the other table name TOCNumberingSchemas,which has 2 columns TOCNumberingSchemaName and TOCHSCounterStyleId.The name will be displayed and id value will be stored in the tableThis is my code for dropdownlist <asp:TemplateField HeaderText="Style"> <EditItemTemplate> <asp:DropDownList ID="DropDownList1" runat="server" datasourceid="SqlDataSource1" SelectedValue='<%#Eval("TOCNumberingSchemaName")%>' datatextfield="TOCNumberingSchemaName" datavaluefield="TOCHSCounterStyleID"></asp:DropDownList></EditItemTemplate> <itemtemplate ><asp:Label ID="lblTAType" runat="server" Text='<%# Bind("TOCNumberingSchemaName") %>'></asp:Label></ItemTemplate></asp:TemplateField>when I am clicking edit button it gives me this errorServer Error in '/comprehensive_plan' Application.'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: valueDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.ArgumentOutOfRangeException: 'DropDownList1' has a SelectedValue which is invalid because it does not exist in the list of items.Parameter name: valueplease helpThank You |
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-10-30 : 14:28:53
|
You have this attribute for your drop-down list:datavaluefield="TOCHSCounterStyleID"This states that the VALUES in the dropdown list are bound to the TOCHSCounterStyleID field.Yet, you are trying to bind the SelectedValue to the TOCNumberingSchemaName field, as shown in your code here:SelectedValue='<%#Eval("TOCNumberingSchemaName")%>'Instead, you need to bind your SelectedValue to the field that populates the Values in your control, which is TOCHSCounterStyleID. So, it should be:SelectedValue='<%#Eval("TOCHSCounterStyleID")%>'Hope this makes sense.- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 14:40:13
|
thanks a lot for the reply,but now its giving me this error DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'TOCHSCounterStyleID'.Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'TOCHSCounterStyleID'.Source Error:Line 29: </EditItemTemplate> Line 30: <itemtemplate >Line 31: <asp:Label ID="lblTAType" runat="server" Text='<%# Bind("TOCHSCounterStyleID")%>'></asp:Label>Line 32: </ItemTemplate>Line 33: please do replythanks |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 14:43:38
|
sorry I pasted it wrong this is the correct one,Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Web.HttpException: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'TOCHSCounterStyleID'.Source Error:Line 24: Line 25: <EditItemTemplate>Line 26: <asp:DropDownList ID="DropDownList1" runat="server" datasourceid="SqlDataSource1" SelectedValue='<%#Eval("TOCHSCounterStyleID")%>' datatextfield="TOCNumberingSchemaName" datavaluefield="TOCHSCounterStyleID">Line 27: Line 28: </asp:DropDownList>Source File: c:\Inetpub\wwwroot\CharlotteCounty\comprehensive_plan\main\edit_schema.aspx Line: 26 |
|
|
jsmith8858
Dr. Cross Join
7423 Posts |
Posted - 2008-10-30 : 15:01:52
|
Then you need to add that column to your data source. Otherwise, how can you bind that ID to a drop-down list if you are not returning the ID from your database?- Jeffhttp://weblogs.sqlteam.com/JeffS |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 16:37:33
|
thank you,that problem solved .But one more problemwhen I am clicking update button,it gives me following errorServer Error in '/comprehensive_plan' Application.Must declare the scalar variable "@TOCHSCounterStyleID".Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.SqlClient.SqlException: Must declare the scalar variable "@TOCHSCounterStyleID".Source Error:An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.I am pasting my datasource code here where I have written my update command.<asp:sqldatasource id="SqlDataSource1" runat="server" connectionstring="<%$ ConnectionStrings:charlotteConnectionString %>" selectcommand="SELECT [TOCHSCounterStyleID], [TOCNumberingSchemaName] FROM [TOCNumberingSchemas]"></asp:sqldatasource> <asp:sqldatasource id="messages" runat="server" connectionstring="<%$ ConnectionStrings:charlotteConnectionString %>" selectcommand="SELECT e.TOCHSLevel,e.TOCHSCounterStyleID,TOCHSPrefixText,t.TOCNumberingSchemaName,e.ShowTOCElement FROM TOCHSElement e left join TOCNumberingSchemas t on e.TOCHSCounterStyleID=t.TOCHSCounterStyleID where TOCHeaderSchemaID=@TOCHeaderSchemaID" updatecommand="UPDATE TOCHSElement SET TOCHSLevel=@TOCHSLevel,TOCHSPrefixText=@TOCHSPrefixText,TOCHSCounterStyleID=@TOCHSCounterStyleID,ShowTOCElement=@ShowTOCElement WHERE TOCHeaderSchemaID=@TOCHeaderSchemaID"> <selectparameters> <asp:querystringparameter name="TOCHeaderSchemaID" querystringfield="id" type="Int32" /> </selectparameters> </asp:sqldatasource>please do replyThanks |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-30 : 17:05:03
|
I solved the error |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-10-30 : 18:31:20
|
Its lot better, neater, scalable to use the objectdatasource rather than the sqldatasource. |
|
|
|
|
|
|
|