none
Error with Edit in GridView using LinqDataSource and DropDownlist RRS feed

  • Question

  • Hi everybody, I´m new here!

    I having much trouble with linqDataSource and my DropDownList when I try to edit in gridView, but I know where is the problem but I don´t have a clue where is the solution!

    The problem:

    Following this tutorial http://weblogs.asp.net/scottgu/archive/2007/05/29/linq-to-sql-part-2-defining-our-data-model-classes.aspx I make my GridView with LinqDataSource working fine, I can edit or delete my entries !

    The real deal is when I trying to edit a row and I have a null value in my DOSESUBCITEM column (where is a DropDownList) nothing happens!!!

     

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" SkinID="TableDefault"
                DataKeyNames="doseitem1" DataSourceID="DOSEITEMLinqDataSource" 
                AllowPaging="True" AllowSorting="True">
                <Columns>
                  <asp:TemplateField HeaderText="Código" SortExpression="codi_item">
                    <ItemTemplate>
                      <asp:Label ID="Label1" runat="server" Text='<%# Bind("codi_item") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:Label ID="Label1" runat="server" Text='<%# Bind("codi_item") %>'></asp:Label>
                    </EditItemTemplate>
                    <HeaderStyle HorizontalAlign="Left" />
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Descrição" SortExpression="desc_item">
                    <ItemTemplate>
                      <asp:Label ID="Label3" runat="server" Text='<%# Bind("desc_item") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:Label ID="Label3" runat="server" Text='<%# Bind("desc_item") %>'></asp:Label>
                    </EditItemTemplate>
                    <HeaderStyle HorizontalAlign="Left" />
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Droga" SortExpression="dosedrog">
                    <ItemTemplate>
                      <asp:Label ID="Label4" runat="server" Text='<%# Bind("dosedrog") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:Label ID="Label4" runat="server" Text='<%# Bind("dosedrog") %>'></asp:Label>
                    </EditItemTemplate>
                    <HeaderStyle HorizontalAlign="Left" />
                  </asp:TemplateField>
                  <asp:TemplateField HeaderText="Genérico" SortExpression="dosegene">
                    <ItemTemplate>
                      <asp:Label ID="Label5" runat="server" Text='<%# Bind("dosegene") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:Label ID="Label5" runat="server" Text='<%# Bind("dosegene") %>'></asp:Label>
                    </EditItemTemplate>
                    <HeaderStyle HorizontalAlign="Left" />
                  </asp:TemplateField>
    
    The Problem is this dropdownlist
    
    
                  <asp:TemplateField HeaderText="Subc. Item" SortExpression="dosesubcitem">
                    <ItemTemplate>
                      <asp:Label ID="Label2" runat="server" 
                        Text='<%# Bind("DOSESUBCITEM1.desc_subc_item") %>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                      <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" AppendDataBoundItems="True" 
                         DataTextField="desc_subc_item" 
                        DataValueField="dosesubcitem1" 
                        SelectedValue='<%# Bind("dosesubcitem") %>' 
                        DataSourceID="DOSESUBCITEMLinqDataSource" >
                        <asp:ListItem Value="null"></asp:ListItem>
                      </asp:DropDownList>
                    </EditItemTemplate>
    
    
                    <HeaderStyle HorizontalAlign="Left" />
                  </asp:TemplateField>
                  <asp:CheckBoxField DataField="stat_subc_item" HeaderText="Ativo" 
                    SortExpression="stat_subc_item" />
                  <asp:CommandField ShowEditButton="True" />
                </Columns>
              </asp:GridView>
    

     

    thanks!

    Monday, February 14, 2011 1:54 AM

All replies

  • Hello Wagner,

     

    Welcome to the MSDN Forum and thanks for posting here.

    According to your description, my understanding is if you choose null value in your DOSESUBCITEM dropdownlist, there is no result return. Am I right?

    If so, I think you may need to add a judgment statement in your behind code. To let return all data if you choose a null value. Then bind to the gridview.

    Please feel free to tell me if I misunderstood you. If so, could you please show us more information about the error and your behind code?

    I hope it can help.

     

    Have a good day,


    Jackie Sun [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, February 17, 2011 7:17 AM
    Moderator