locked
In editable gridview problem with updating dropdownlist RRS feed

  • Question

  • User592970785 posted

     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 columns
    TOCHSElementID pk
    TOCHSLevel
    TOCHSPrefixText
    TOCHSCounterStyleID
    ShowTOCElement.


    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 behind

    Please 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 

    1    Hello
    2    In my editable gridview i have dropdownlist which is bound to a table named TOCNumberingSchemas,which has 2 columns,TOCHSCounterSTyleID and TOCNumberingSchemaName.
    3    For example
    4    TOCNumberingSchemaName = Uppercase and its corresponding TOCHSCounterSTyleID=34.
    5    
    6    My Dropdownlist when editing gridview will show TOCNumberingSchemaName but it will insert TOCHSCounterSTyleID i.e. value.(because table TOCHSElement have column name TOCHSCounterStyleID)
    7    
    8    My Gridview will update data of the table TOCHSElement,which has following columns
    9    TOCHSElementID pk
    10   TOCHSLevel
    11   TOCHSPrefixText
    12   TOCHSCounterStyleID
    13   ShowTOCElement.
    14   
    15   
    16   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.
    17   
    18   I am pasting my entire code,and also I have not written anything in my code behind
    19   
    20   Please help me
    21   
    22   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="edit_schema.aspx.cs" Inherits="main_edit_schema"
    23   title="TOC Schemas" masterpagefile="~/template/base/template_base.master" %>
    24   <asp:content id="<span" class="st">"Content3" contentplaceholderid="RegionMiddle" runat="server">
    25   
    26   <asp:gridview id="<span" class="st">"msgsGrid" runat="server"
    27   datasourceid="messages"
    28   datakeynames="TOCHSElementID"
    29   
    30   autogeneratecolumns="false"
    31   autogenerateeditbutton="true">
    32   
    33   
    34   <columns>
    35   
    36   <asp:boundfield headertext="<span" class="st">"Level"
    37   datafield="TOCHSLevel" />
    38   
    39   <asp:boundfield headertext="<span" class="st">"Prefix"
    40   datafield="TOCHSPrefixText" />
    41   
    42   <asp:templatefield headertext="<span" class="st">"Style">
    43   
    44   <edititemtemplate>
    45   <asp:dropdownlist id="<span" class="st">"DDL1" runat="server" datasourceid="SqlDataSource1" SelectedValue='<%#Eval("TOCHSCounterStyleID")%>' datatextfield="TOCNumberingSchemaName" datavaluefield="TOCHSCounterStyleID">
    46   
    47   </asp:dropdownlist>
    48   </edititemtemplate>
    49   <itemtemplate>
    50   <asp:label id="<span" class="st">"lblTAType" runat="server" Text='<%# Bind("TOCNumberingSchemaName")%>'></asp:label>
    51   </itemtemplate>
    52   
    53   </asp:templatefield>
    54   <asp:templatefield headertext="<span" class="st">"Visibility">
    55   <edititemtemplate>
    56   <asp:checkbox id="<span" class="st">"chkActiveStatus"
    57   runat="server" SelectedValue='<%#Eval("ShowTOCElement")%>' Checked='<%# Bind("ShowTOCElement")%>' />
    58   
    59   </asp:checkbox>
    60   <itemtemplate>
    61   <asp:label id="<span" class="st">"lblTAType1" runat="server" Text='<%# Bind("ShowTOCElement")%>'></asp:label>
    62   </itemtemplate>
    63   </edititemtemplate>
    64   
    65   
    66   
    67   
    68   </asp:templatefield>
    69   
    70   
    71   </asp:boundfield>
    72   <asp:sqldatasource id="<span" class="st">"SqlDataSource1" runat="server" connectionstring="&lt;%$ ConnectionStrings:charlotteConnectionString %>" selectcommand="SELECT [TOCHSCounterStyleID], [TOCNumberingSchemaName] FROM [TOCNumberingSchemas]"></asp:sqldatasource>
    73   <asp:sqldatasource id="<span" class="st">"messages" runat="server" connectionstring="&lt;%$ ConnectionStrings:charlotteConnectionString %>"
    74   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"
    75   updatecommand="UPDATE TOCHSElement SET
    76   TOCHSLevel=@TOCHSLevel,TOCHSCounterStyleID=@TOCHSCounterSTyleID,TOCHSPrefixText=@TOCHSPrefixText,ShowTOCElement=@ShowTOCElement
    77   WHERE TOCHSElementID=@TOCHSElementID">
    78   <updateparameters>
    79   <asp:parameter name="<span" class="st">"TOCHSLevel" Type="Int32" />
    80   <asp:parameter name="<span" class="st">"TOCHSPrefixText" type ="String"/>
    81   <asp:parameter name="<span" class="st">"TOCHSCounterStyleID" type ="Int32"/>
    82   <asp:parameter name="<span" class="st">"ShowTOCElement" type ="Boolean"/>
    83   
    84   <asp:parameter name="<span" class="st">"TOCHSElementID" type ="Int32"/>
    85   </asp:parameter>
    86   <selectparameters>
    87   <asp:querystringparameter name="<span" class="st">"TOCHeaderSchemaID" querystringfield="id" type="Int32" />
    88   </asp:querystringparameter>
    89   </selectparameters>
    90   
    91   
    92   </asp:parameter>
    93   
    94   Thank You
    </asp:parameter></asp:parameter></asp:parameter></updateparameters></asp:sqldatasource></asp:boundfield></columns></asp:gridview></asp:content>
     

    Thursday, October 30, 2008 7:23 PM

Answers

  • User-1635004338 posted

    Hi bluestarmoon,

    Try to change to :

    SelectedValue='<%#Bind("TOCHSCounterStyleID")%>'

    Thanks,

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, November 4, 2008 4:05 AM