Error Binding SQLDataSource to ASP TextBox in RadPanel

3 posts, 0 answers
  1. Gunjan
    Gunjan avatar
    12 posts
    Member since:
    Apr 2009

    Posted 01 May 2009 Link to this post

    The RadPanel is not binding the data to my sqlDataSource. I keep getting "field cannot be NULL" when trying to insert the data to the db.

    Here is my part of my code:
    <asp:SqlDataSource ID="sqlDSProjInfo" runat="server"  
        ConnectionString="<%$ ConnectionStrings:JOBTRAKConnectionString %>"  
        InsertCommand="INSERT INTO [CASE_PROJ_INFO] ([JOB_ID], [CASE_NAME], [MEDIA], [MEDIA_LOC], [MEDIA_AVAIL], [MEDIA_SIZE]) VALUES (@JOB_ID, @CASE_NAME, @MEDIA, @MEDIA_LOC, @MEDIA_AVAIL, @MEDIA_SIZE)"  
        SelectCommand="SELECT * FROM [CASE_PROJ_INFO] WHERE [JOB_ID] = @JOB_ID" 
        UpdateCommand="UPDATE [CASE_PROJ_INFO] SET [CASE_NAME] = @CASE_NAME, [MEDIA] = @MEDIA, [MEDIA_LOC] = @MEDIA_LOC, [MEDIA_AVAIL] = @MEDIA_AVAIL, [MEDIA_SIZE] = @MEDIA_SIZE WHERE [JOB_ID] = @JOB_ID">
        <UpdateParameters> 
            <asp:SessionParameter Name="CASE_NAME" SessionField="CASE_NAME" Type="String" /> 
            <asp:SessionParameter Name="MEDIA" SessionField="MEDIA" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_LOC" SessionField="MEDIA_LOC" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_AVAIL" SessionField="MEDIA_AVAIL" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_SIZE" SessionField="MEDIA_SIZE" Type="String" /> 
            <asp:SessionParameter Name="JOB_ID" SessionField="JOB_ID" Type="String" /> 
        </UpdateParameters> 
        <InsertParameters> 
            <asp:Parameter Name="JOB_ID" Type="String" /> 
            <asp:SessionParameter Name="CASE_NAME" SessionField="CASE_NAME" Type="String" /> 
            <asp:SessionParameter Name="MEDIA" SessionField="MEDIA" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_LOC" SessionField="MEDIA_LOC" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_AVAIL" SessionField="MEDIA_AVAIL" Type="String" /> 
            <asp:SessionParameter Name="MEDIA_SIZE" SessionField="MEDIA_SIZE" Type="String" /> 
        </InsertParameters> 
        <SelectParameters> 
            <asp:Parameter Name="JOB_ID" Type="String" /> 
        </SelectParameters> 
    </asp:SqlDataSource> 
     
    <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" Height="554px" Width="742px"
        <telerik:RadPanelBar ID="RadPanelBar1" Runat="server" Height="100%" DataSourceID="sqlDSProjInfo" 
            Width="100%" AllowCollapseAllItems="True" ExpandMode="SingleExpandedItem"
            <CollapseAnimation Duration="100" Type="None" /> 
            <Items> 
                <telerik:RadPanelItem Expanded="true" Text="Project Information" runat="server"
                    <Items> 
                        <telerik:RadPanelItem runat="server" Value="Project Information"
                            <ItemTemplate> 
                                <div> 
                                    <p> 
                                        <table style="width: 100%"
                                            <tr> 
                                                <td> 
                                                    <asp:Label ID="lblCaseName" runat="server" Text="Case Name" /> 
                                                </td> 
                                                <td colspan="3"
                                                    <asp:TextBox ID="CASE_NAME" runat="server" Text='<%# Eval("CASE_NAME") %>' /> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <asp:Label ID="lblMedia" runat="server" Text="Media:" /> 
                                                </td> 
                                                <td> 
                                                    <asp:TextBox ID="MEDIA" runat="server" Text='<%# Eval("MEDIA") %>' /> 
                                                </td> 
                                                <td> 
                                                    <asp:Label ID="lblMediaAvail" runat="server" Text="Media Availability:" /> 
                                                </td> 
                                                <td> 
                                                    <asp:TextBox ID="MEDIA_AVAIL" runat="server" Text='<%# Eval("MEDIA_AVAIL") %>' /> 
                                                </td> 
                                            </tr> 
                                            <tr> 
                                                <td> 
                                                    <asp:Label ID="lblMediaLoc" runat="server" Text="Media Location:" /> 
                                                </td> 
                                                <td> 
                                                    <asp:TextBox ID="MEDIA_LOC" runat="server" Text='<%# Eval("MEDIA_LOC") %>' /> 
                                                </td> 
                                                <td> 
                                                    <asp:Label ID="lblMediaSize" runat="server" Text="Media Size (GB):" /> 
                                                </td> 
                                                <td> 
                                                    <asp:TextBox ID="MEDIA_SIZE" runat="server" Text='<%# Eval("MEDIA_SIZE") %>' /> 
                                                </td> 
                                            </tr> 
                                        </table> 
                                    </p> 
                                </div> 
                            </ItemTemplate> 
                        </telerik:RadPanelItem> 
                    </Items> 
                </telerik:RadPanelItem> 
            </Items> 
            <ExpandAnimation Duration="100" Type="None" /> 
        </telerik:RadPanelBar> 
     
     
     

    Thanks,

    Gunjan
  2. Gunjan
    Gunjan avatar
    12 posts
    Member since:
    Apr 2009

    Posted 06 May 2009 Link to this post

    I made some changes to my code:

    1) Using FormParameters instead of SessionParameters
    2) Using Bind instead of Eval
    3) Putting the table inside <asp:FormView><asp:ItemTemplate> (existing table code) </asp:ItemTemplate></asp:FormView>

    Option 3 allowed me to bind the textboxes to the sqldatasource. Is this the correct way to bind the data? Shouldn't the DataSourceID defined in the <RadPanelBar> work? I've been trying to find some documentation on the RadPanelBar, but haven't found anything relevent. I'm using the RadPanelBar to mimic a web form.

    Thanks,

    Gunjan
  3. Gunjan
    Gunjan avatar
    12 posts
    Member since:
    Apr 2009

    Posted 08 May 2009 Link to this post

    I was way off w/ my code. I'm used to C & C++ coding in unix, so moving to ASP.NET has been interesting.

    Here is an example of the code I'm using. Please let me know if this is a correct method or if there is an easier solution. I added some code in the backend to initialize each formview in edit/insert mode, and a save button to call the FormView.InsertItem(bool) or FormView.UpdateItem(bool) methods. Not sure if this will help anyone or not, but I didn't see any examples of creating a form using the RadPanel.

    <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:SqlConnectionString %>" 
      InsertCommand="..." 
      SelectCommand="..." 
      UpdateCommand="..." 
      <SelectParameters> 
        <asp:QueryStringParameter Name="..." QueryStringFormat="..." Type="String" /> 
        ... 
      </SelectParameters> 
      <InsertParameters> 
        <asp:Parameter Name="..." Type="..." /> 
        ... 
      </InsertParameters> 
      <UpdateParameters> 
        <asp:Parameter Name="..." Type="..." /> 
        ... 
      </UpdateParameters> 
     
      <telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server"
        <telerik:RadPanelBar ID="RadPanelBar1" runat="server"
          <Items> 
            <telerik:RadPanelItem ID="RadPanelItem1" runat="server"
              <ItemTemplate> 
                <asp:FormView ID="FormView1" runat="server" DataSourceID="SqlDataSource1"
                  <EditItemTemplate> 
                    <RadioButtonList ID="RadioButtonList1" runat="server" SelectedValue='<%# Bind("COL1") %>'
                      <asp:ListItem ... /> 
                    </RadioButtonList> 
                    <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("COL2") %> /> 
                  </EditItemTemplate> 
                  <InsertItemTemplate> 
                    ... 
                  </InsertItemTemplate> 
                </asp:FormView> 
              </ItemTemplate> 
            </telerik:RadPanelItem> 
          </Items> 
        </telerik:RadPanelBar> 
      </telerik:RadAjaxPanel> 

Back to Top