Как вставить запись в базу данных, используя RadControls для ASP.NET AJAX - PullRequest
0 голосов
/ 12 мая 2011

У меня есть небольшое приложение на asp.net, в котором я использую RadControls для ASP.NET AJAX telrik, когда я пытаюсь вставить запись, которую не вставляю в базу данных, но она работает, выберите команду, и любой может мне помочь, пожалуйста, здесья отправляю свой код ...

<% @ Register TagPrefix = "sds" Namespace = "Telerik.Web.SessionDS"%> <% @ Register TagPrefix = "telerik" Namespace = "Telerik.Web.UI"Assembly =" Telerik.Web.UI "%> <% - <% @ Register TagPrefix =" qsf "Namespace =" Telerik.QuickStart "%> -%> <% - -%>

    <script type="text/javascript">
    // <![CDATA[
        //On insert and update buttons click temporarily disables ajax to perform upload actions
        function conditionalPostback(sender, eventArgs) {
            var theRegexp = new RegExp("\.UpdateButton$|\.PerformInsertButton$", "ig");
            if (eventArgs.get_eventTarget().match(theRegexp)) {
                var upload = $find(window['UploadId']);

                //AJAX is disabled only if file is selected for upload
                if (upload.getFileInputs()[0].value != "") {
                    eventArgs.set_enableAjax(false);
                }
            }
        }

        function validateRadUpload(source, e) {
            e.IsValid = false;

            var upload = $find(source.parentNode.getElementsByTagName('div')[0].id);
            var inputs = upload.getFileInputs();
            for (var i = 0; i < inputs.length; i++) {
                //check for empty string or invalid extension
                if (inputs[i].value != "" && upload.isExtensionValid(inputs[i].value)) {
                    e.IsValid = true;
                    break;
                }
            }
        }
        // ]]>
    </script>

</telerik:RadCodeBlock>
<telerik:RadAjaxPanel ID="RadAjaxPanel1" runat="server" ClientEvents-OnRequestStart="conditionalPostback">
    <telerik:RadProgressManager ID="RadProgressManager1" runat="server" />
    <telerik:RadProgressArea ID="RadProgressArea1" runat="server" />
    <telerik:RadGrid runat="server" ID="RadGrid1" AllowPaging="True" AllowSorting="True"
        AutoGenerateColumns="False" Width="97%" DataSourceID="SqlDataSource1" AllowAutomaticInserts="true"
        AllowAutomaticUpdates="true" AllowAutomaticDeletes="true" ShowStatusBar="True"
        GridLines="None" OnItemDataBound="RadGrid1_ItemDataBound" OnItemCreated="RadGrid1_ItemCreated" PageSize="3">
        <PagerStyle Mode="NumericPages" AlwaysVisible="true" />
        <MasterTableView Width="100%" CommandItemDisplay="Top" DataKeyNames="ID" DataSourceID="SqlDataSource1">
            <Columns>
                <telerik:GridEditCommandColumn ButtonType="ImageButton">
                    <HeaderStyle Width="3%" />
                </telerik:GridEditCommandColumn>
                <telerik:GridTemplateColumn HeaderText="Image Name" UniqueName="ImageName" SortExpression="Name">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lblName" Text='<%# Eval("Name") %>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox runat="server" Width="200px" ID="txbName" Text='<%# Bind("Name") %>' />
                        <asp:RequiredFieldValidator ID="Requiredfieldvalidator1" runat="server" ControlToValidate="txbName" ErrorMessage="Please, enter a name!" Display="Dynamic" SetFocusOnError="true" />
                    </EditItemTemplate>
                    <HeaderStyle Width="30%" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Description" UniqueName="Description" DataField="Description">
                    <ItemTemplate>
                        <asp:Label ID="lblDescription" runat="server" Text='<%# Eval("Description")%>' />
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadTextBox ID="txbDescription" Width="300px" runat="server" TextMode="MultiLine"
                            Text='<%# Bind("Description") %>' Height="150px" />
                    </EditItemTemplate>
                    <ItemStyle VerticalAlign="Top" />
                </telerik:GridTemplateColumn>
                <telerik:GridBinaryImageColumn DataField="Data" HeaderText="Image" UniqueName="Upload" ImageAlign="NotSet"
                    ImageHeight="80px" ImageWidth="80px" ResizeMode="Fit" DataAlternateTextField="Description"
                    DataAlternateTextFormatString="Image of {0}">
                    <HeaderStyle Width="10%" /> 
                </telerik:GridBinaryImageColumn>
                <telerik:GridButtonColumn Text="Delete" CommandName="Delete" ButtonType="ImageButton">
                    <HeaderStyle Width="2%" />
                </telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings>
                <EditColumn ButtonType="ImageButton" />
            </EditFormSettings>
        </MasterTableView> 
    </telerik:RadGrid> 
</telerik:RadAjaxPanel>
  <sds:SessionDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
    SelectCommand="SELECT * FROM [Mybusinessapp_Pictures]" InsertCommand="INSERT INTO [Mybusinessapp_Pictures] ([Name], [Description], [Data]) VALUES (@Name, @Description, @Data)"
    UpdateCommand="UPDATE [Mybusinessapp_Pictures] SET [Name] = @Name, [Description] = @Description, [Data] = @Data WHERE [ID] = @ID"
    DeleteCommand="DELETE FROM [Mybusinessapp_Pictures] WHERE [ID] = @ID" PrimaryKeyFields="ID" SessionKey="UploadGridCS">
    <InsertParameters>
        <asp:Parameter Name="Name" Type="String" />
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="Data" DbType="Binary" />
    </InsertParameters>
    <UpdateParameters>
        <asp:Parameter Name="Name" Type="String" />
        <asp:Parameter Name="Description" Type="String" />
        <asp:Parameter Name="ID" Type="Int32" />
    </UpdateParameters>
      <%--  <asp:Parameter Name="Data" DbType="Binary" />--%>
    <DeleteParameters>
        <asp:Parameter Name="ID" Type="Int32" />
    </DeleteParameters>
</sds:SessionDataSource>

<% - -%>

1 Ответ

1 голос
/ 03 августа 2011

Измените свою SessionDataSource InsertCommand на:

InsertCommand = "INSERT INTO [Mybusinessapp_Pictures] ([Имя], [Описание], [Данные]) VALUES (?,?,?)"

...