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 : 19:21:57
|
Hello In my editable gridview i have dropdownlist which is bound to a table named TOCNumberingSchemas,which has 2 columns,TOCHSCounterSTyleID and TOCNumberingSchemaName.For example TOCNumberingSchemaName = Uppercase and its corresponding TOCHSCounterSTyleID=34.My Dropdownlist when editing gridview will show TOCNumberingSchemaName but it will insert TOCHSCounterSTyleID i.e. value.(because table TOCHSElement have column name TOCHSCounterStyleID)My Gridview will update data of the table TOCHSElement,which has following columnsTOCHSElementID pkTOCHSLevelTOCHSPrefixTextTOCHSCounterStyleIDShowTOCElement.My problem is when ever I am updating dropdownlist its give me error cannot insert null value to TOCHSCounterStyleID.That means its not getting Value from the dropdownlist.I am pasting my entire code,and also I have not written anything in my code behindPlease help me<%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit_schema.aspx.cs" Inherits="main_edit_schema" title="TOC Schemas" masterpagefile="~/template/base/template_base.master" %><asp:content id="Content3" contentplaceholderid="RegionMiddle" runat="server"> <asp:gridview id="msgsGrid" runat="server" datasourceid="messages" datakeynames="TOCHSElementID" autogeneratecolumns="false" autogenerateeditbutton="true"> <columns > <asp:boundfield headertext="Level" datafield="TOCHSLevel" /> <asp:boundfield headertext="Prefix" datafield="TOCHSPrefixText" /> <asp:TemplateField HeaderText="Style"> <EditItemTemplate> <asp:DropDownList ID="DDL1" runat="server" datasourceid="SqlDataSource1" SelectedValue='<%#Eval("TOCHSCounterStyleID")%>' datatextfield="TOCNumberingSchemaName" datavaluefield="TOCHSCounterStyleID"></asp:DropDownList></EditItemTemplate> <itemtemplate ><asp:Label ID="lblTAType" runat="server" Text='<%# Bind("TOCNumberingSchemaName")%>'></asp:Label></ItemTemplate></asp:TemplateField><asp:TemplateField HeaderText="Visibility"><EditItemTemplate><asp:CheckBox ID="chkActiveStatus" runat="server" SelectedValue='<%#Eval("ShowTOCElement")%>' Checked='<%# Bind("ShowTOCElement")%>' /></EditItemTemplate><itemtemplate><asp:Label ID="lblTAType1" runat="server" Text='<%# Bind("ShowTOCElement")%>'></asp:Label></itemtemplate> </asp:TemplateField> </columns> </asp:gridview><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.TOCHSElementID,e.TOCHSLevel,e.TOCHSCounterStyleID,e.TOCHSPrefixText,t.TOCNumberingSchemaName,e.ShowTOCElement FROM TOCHSElement e ,TOCNumberingSchemas t Where e.TOCHSCounterStyleID=t.TOCHSCounterStyleID AND TOCHeaderSchemaID=@TOCHeaderSchemaID" updatecommand="UPDATE TOCHSElement SET TOCHSLevel=@TOCHSLevel,TOCHSCounterStyleID=@TOCHSCounterSTyleID,TOCHSPrefixText=@TOCHSPrefixText,ShowTOCElement=@ShowTOCElement WHERE TOCHSElementID=@TOCHSElementID"> <UpdateParameters> <asp:Parameter Name="TOCHSLevel" Type="Int32" /> <asp:parameter name ="TOCHSPrefixText" type ="String"/> <asp:parameter name ="TOCHSCounterStyleID" type ="Int32"/> <asp:parameter name ="ShowTOCElement" type ="Boolean"/> <asp:parameter name="TOCHSElementID" type ="Int32"/> </UpdateParameters> <selectparameters> <asp:querystringparameter name="TOCHeaderSchemaID" querystringfield="id" type="Int32" /> </selectparameters> </asp:sqldatasource> </asp:content>Thank You |
|
cvraghu
Posting Yak Master
187 Posts |
Posted - 2008-10-31 : 05:59:25
|
Use ControlParameters to bind control values to UpdateParameters. Refer to http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.sqldatasource.updateparameters.aspx |
|
|
bluestar
Posting Yak Master
133 Posts |
Posted - 2008-10-31 : 10:19:19
|
Thanks for reply ,I did exactly what you said. <UpdateParameters> <asp:Parameter Name="TOCHSLevel" Type="Int32" /> <asp:parameter name ="TOCHSPrefixText" type ="String"/> <asp:ControlParameter name ="TOCHSCounterStyleID" ControlId="DDL1" PropertyName="SelectedValue"/> <asp:parameter name ="ShowTOCElement" type ="Boolean"/> <asp:parameter name="TOCHSElementID" type ="Int32"/> </UpdateParameters>But now its giving me error Server Error in '/comprehensive_plan' Application.Could not find control 'DDL1' in ControlParameter '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.InvalidOperationException: Could not find control 'DDL1' in ControlParameter '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.please helpThnak You |
|
|
|
|
|
|
|