This is a migrated thread and some comments may be shown as answers.

How Can I update the radgrid data

1 Answer 97 Views
Grid
This is a migrated thread and some comments may be shown as answers.
bin zhang
Top achievements
Rank 1
bin zhang asked on 15 Sep 2010, 03:21 AM
     Hi everybody.
      My database is oracle. and i use sqldatasource to access database. My RadGrid's datasource is the sqldatatabase. the oracle database have no bool datatype. So some fields i used the number 0 and 1 instead. the 1 is true and the 0 is false.  in the radgrid. I show the field by checkbox. the code like this:
  <telerik:GridTemplateColum>
     <ItemTemplate>
         <asp:CheckBox id="chkBool" checked='<%# DataBinder(Container,"DataItem.SomeField").ToString()=="1"?true:false %>' />
    </ItemTemplate>
  </telerik:GridTemplateColum>
     And In my edit form. I also use the CheckBox like this 
 <asp:CheckBox id="chkBool" checked='<%# DataBinder(Container,"DataItem.SomeField").ToString()=="1"?true:false %>' /> 
   so  how can it automatic update or insert the data to oracle?
     And when I want to Update a row by edit form, How can i update the data? And How do i write the Sqldatasource's updatecommand?


<%@ Page Title="" Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="DataEditor.aspx.cs" Inherits="Default2" %>
<%@ Register TagPrefix="sds" Namespace="Telerik.Web.SessionDS" %>
<asp:Content ID="Content1"  ContentPlaceHolderID="GlobeContentPH" Runat="Server">
    <link href="styles/style/css/main.css" rel="stylesheet" type="text/css" />
     <style type="text/css">
        .MyImageButton
        {
           cursor: hand;
        }
        .EditFormHeader td
        {
            font-size: 14px;
            padding: 4px !important;
            color: #0066cc;
        }
        </style>

 <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
            <AjaxSettings>
                <telerik:AjaxSetting AjaxControlID="RadGrid1">
                    <UpdatedControls>
                        <telerik:AjaxUpdatedControl ControlID="RadGrid1" />
                    </UpdatedControls>
                </telerik:AjaxSetting>
            </AjaxSettings>
        </telerik:RadAjaxManager>
<table style=" width:100%; border:0px">
  <tr style=" width:100%">
      <td style=" width:100%">
      <div id="RadGrid" style="width:100%">
 
   <telerik:RadGrid ID="RadGrid1" AllowAutomaticUpdates="True" Width="100%"   AllowAutomaticDeletes="True"
            DataSourceID="SqlDataSource1" AllowSorting="True"
            AllowPaging="True" runat="server" ShowFooter="True" AllowMultiRowSelection="True"
            PageSize="20" AllowMultiRowEdit="True" AllowAutomaticInserts="True"  OnItemUpdated="RadGrid1_ItemUpdated"
         Skin="Vista" GridLines="None">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView Width="100%" CommandItemDisplay="Top"
                DataSourceID="SqlDataSource1" AutoGenerateColumns="False">
                <Columns>
                    <telerik:GridBoundColumn DataField="序号" DataType="System.Decimal"
                        HeaderText="序号" SortExpression="序号" UniqueName="序号">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="作业区" HeaderText="作业区" SortExpression="作业区"
                        UniqueName="作业区">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="监测点代号" DataType="System.Decimal"
                        HeaderText="监测点代号" SortExpression="监测点代号" UniqueName="监测点代号">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="监测点名称" HeaderText="监测点名称"
                        SortExpression="监测点名称" UniqueName="监测点名称">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="监测点部位" HeaderText="监测点部位"
                        SortExpression="监测点部位" UniqueName="监测点部位">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="建点日期" DataType="System.DateTime"
                        HeaderText="建点日期" SortExpression="建点日期" UniqueName="建点日期">
                    </telerik:GridBoundColumn>
        
                    <telerik:GridBoundColumn DataField="氢探针" HeaderText="氢探针" SortExpression="氢探针"
                        UniqueName="氢探针" DataType="System.Decimal">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="电阻探针" HeaderText="电阻探针"
                        SortExpression="电阻探针" UniqueName="电阻探针" DataType="System.Decimal">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="试片失重法" HeaderText="试片失重法"
                        SortExpression="试片失重法" UniqueName="试片失重法" DataType="System.Decimal">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="介质"
                        HeaderText="介质" SortExpression="介质" UniqueName="介质">
                    </telerik:GridBoundColumn>
                    
                    <telerik:GridBoundColumn DataField="管线材质" HeaderText="管线材质" SortExpression="管线材质"
                        UniqueName="管线材质">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="管线规格" HeaderText="管线规格"
                        SortExpression="管线规格" UniqueName="管线规格">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="报废日期" HeaderText="报废日期"
                        SortExpression="报废日期" UniqueName="报废日期" DataType="System.DateTime">
                    </telerik:GridBoundColumn>
                 <%--   <telerik:GridBoundColumn DataField="是否现用" HeaderText="是否现用"
                        SortExpression="是否现用" UniqueName="是否现用" DataType="System.Decimal">
                    </telerik:GridBoundColumn>--%>
                    <telerik:GridTemplateColumn DataField="是否现用" HeaderText="是否现用"
                        SortExpression="是否现用" UniqueName="是否现用">
                        <ItemTemplate>
                           <asp:CheckBox ID="CheckBox1" Checked='<%# (DataBinder.Eval( Container, "DataItem.是否现用")).ToString()=="1"?true:false %>' runat="server" />
                        </ItemTemplate>
                    </telerik:GridTemplateColumn>
                    <telerik:GridBoundColumn DataField="备注" HeaderText="备注" SortExpression="备注"
                        UniqueName="备注">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="管道名称" HeaderText="管道名称"
                        SortExpression="管道名称" UniqueName="管道名称">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="场站名称" HeaderText="场站名称"
                        SortExpression="场站名称" UniqueName="场站名称">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn DataField="照片ID" HeaderText="照片ID"
                        SortExpression="照片ID" UniqueName="照片ID">
                    </telerik:GridBoundColumn>
                </Columns>
              <EditFormSettings EditFormType="Template">
                    <FormTemplate>
                       <div>
                          <div id="show_title"></div>
                          <div id="show_area"></div>
                          <div id="show_main_edit">
                            <table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
                               <tr>
                                <td class="show_main_td_first" >序&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 号:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox  Width="80%" ID="PipsegmentCode" Text='<%# DataBinder.Eval( Container, "DataItem.序号" ) %>' runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_last">作 业 区:</td>
                                <td class="show_main_td_last">
                                      <asp:DropDownList ID="DropDownList1" Width="39%" runat="server">
                                    </asp:DropDownList>
                                    <asp:DropDownList ID="DropDownList2" Width="39%" runat="server">
                                    </asp:DropDownList>
                        &nbsp; </td>
                              </tr>
                                <tr>
                                <td class="show_main_td_first" >监测点代号:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox Width="80%" ID="PipeSegmentLength" Text='<%# DataBinder.Eval( Container, "DataItem.监测点代号" ) %>' runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_last">监测点名称:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox runat="server"  Text='<%# DataBinder.Eval( Container, "DataItem.监测点名称" ) %>'   Width="80%" ID="PipeDiameter"></asp:TextBox>
                                            </td>
                              </tr>
                              <tr>
                                <td class="show_main_td_first">监测点部位:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="PipeThickness" Text='<%# DataBinder.Eval( Container, "DataItem.监测点部位" ) %>'  Width="80%" runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_last">管线规格:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="SteelClass" Text='<%# DataBinder.Eval( Container, "DataItem.管线规格" ) %>'  Width="80%" runat="server"></asp:TextBox>
                                            </td>
                              </tr>
                                <tr>
                                <td class="show_main_td_first" >管线材质:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="MadeStyle" Text='<%# DataBinder.Eval( Container, "DataItem.管线材质" ) %>'  Width="80%" runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_last">介&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 质:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="JointMethod" Text='<%# DataBinder.Eval( Container, "DataItem.介质" ) %>' Width="80%" runat="server"></asp:TextBox>
                                            </td>
                              </tr>
                              <tr>
                                <td class="show_main_td_first">试片失重法:</td>
                                <td class="show_main_td_last">
                                      <%--<asp:DropDownList ID="DropDownList3" SelectedValue='<%# DataBinder.Eval( Container, "DataItem.试片失重法" ) %>'    Width="80%" runat="server">
                                       <asp:ListItem Value="1" Text="是"></asp:ListItem>                                  
                                       <asp:ListItem Value="0" Text="否"></asp:ListItem>
                                    </asp:DropDownList>  --%>
                                     <asp:CheckBox ID="chkSPSZF" Checked='<%# (DataBinder.Eval( Container, "DataItem.试片失重法")).ToString()=="1"?true:false %>' runat="server" />
                                            </td>
                                <td class="show_main_td_last">电阻探针:</td>
                                <td class="show_main_td_last">
                                  <%--  <asp:DropDownList ID="DropDownList4" SelectedValue='<%# Bind("电阻探针") %>'   Width="80%" runat="server">
                                       <asp:ListItem Value="1" Text="是"></asp:ListItem>                                  
                                       <asp:ListItem Value="0" Text="否"></asp:ListItem>
                                    </asp:DropDownList> --%> <asp:CheckBox ID="chkDZTZ" Checked='<%# (DataBinder.Eval( Container, "DataItem.电阻探针")).ToString()=="1"?true:false %>' runat="server" />
                                            </td>
                              </tr>
                                <tr>
                                <td class="show_main_td_first" >氢探针:</td>
                                <td class="show_main_td_last">
                                    <asp:CheckBox ID="chkQTZ" Checked='<%# (DataBinder.Eval( Container, "DataItem.氢探针")).ToString()=="1"?true:false %>' runat="server" />
                                            </td>
                                <td class="show_main_td_last">建点日期:</td>
                                <td class="show_main_td_last">
                                    <telerik:RadDatePicker ID="RadDatePicker2"   DbSelectedDate='<%# DataBinder.Eval( Container, "DataItem.建点日期" ) %>' Width="80%"   runat="server" >
                                      <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x">
                                      </Calendar>
                                       <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>
                                     <DateInput DisplayDateFormat="yyyy-M-d"   DateFormat="yyyy-M-d"></DateInput>
                                    </telerik:RadDatePicker>

                                            </td>
                              </tr>
                                <tr>
                                <td class="show_main_td_first" >报废日期:</td>
                                <td class="show_main_td_last">
                                    <telerik:RadDatePicker ID="RadDatePicker1" DbSelectedDate='<%# DataBinder.Eval( Container, "DataItem.报废日期" ) %>'   Width="80%" runat="server" >

                        <Calendar UseRowHeadersAsSelectors="False" UseColumnHeadersAsSelectors="False" ViewSelectorText="x"></Calendar>

                        <DatePopupButton ImageUrl="" HoverImageUrl=""></DatePopupButton>

                        <DateInput DisplayDateFormat="yyyy-M-d" DateFormat="yyyy-M-d"></DateInput>
                                    </telerik:RadDatePicker>

                                            </td>
                                <td class="show_main_td_last">是否现用:</td>
                                <td class="show_main_td_last">
                                    <asp:CheckBox ID="CheckBox1" Checked='<%# (DataBinder.Eval( Container, "DataItem.是否现用")).ToString()=="1"?true:false %>' runat="server" />
                                            </td>
                              </tr>
                                <tr>
                                <td class="show_main_td_first" >管道名称:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="EFFECTIVEFROMDATE" Text='<%# DataBinder.Eval( Container, "DataItem.管道名称" ) %>' Width="80%" runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_first">站场名称:</td>
                                <td class="show_main_td_last">
                                 <asp:TextBox ID="TextBox2" Text='<%# DataBinder.Eval( Container, "DataItem.场站名称" ) %>' Width="80%" runat="server"></asp:TextBox>
                                </td>
                              </tr>
                                   <tr>
                                <td class="show_main_td_first" >照片ID:</td>
                                <td class="show_main_td_last">
                                    <asp:TextBox ID="TextBox1" Text='<%# DataBinder.Eval( Container, "DataItem.照片ID" ) %>' Width="80%" runat="server"></asp:TextBox>
                                            </td>
                                <td class="show_main_td_last">&nbsp; </td>
                                <td class="show_main_td_last">&nbsp;</td>
                              </tr>
                                  
                              <tr>
                                <td class="show_main_td_first">备&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注</td>
                                <td colspan="4" class="show_main_td_last">
                                <asp:TextBox ID="TextBox3" Text='<%# DataBinder.Eval( Container, "DataItem.备注" ) %>' TextMode="MultiLine" Width="90%" runat="server"></asp:TextBox></td>
                              </tr>

                            </table>
                            <div id="show_main_do">
                              <asp:Button ID="btnUpdate" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>'
                                        runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'>
                                    </asp:Button>&nbsp;
<asp:Button ID="btnCancel" Text="Cancel" runat="server" CausesValidation="False"
CommandName="Cancel"></asp:Button>
                        </div>
                          </div>
                        </div>
                    </FormTemplate>
               </EditFormSettings>

                    <CommandItemTemplate>
                    <div style="padding: 5px 5px;">
                        监测点信息表操作:&nbsp;&nbsp;&nbsp;&nbsp;
                        <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# RadGrid1.EditIndexes.Count == 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Edit.gif" />编辑选择项</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# RadGrid1.EditIndexes.Count > 0 %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Update.gif" />更新</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" Visible='<%# RadGrid1.EditIndexes.Count > 0 || RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Cancel.gif" />取消编辑</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/AddRecord.gif" />添加新监测点</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# RadGrid1.MasterTableView.IsItemInserted %>'><img style="border:0px;vertical-align:middle;" alt="" src="Images/Insert.gif" /> Add this Customer</asp:LinkButton>&nbsp;&nbsp;
<asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('删除所有选择的监测点吗?')"
runat="server" CommandName="DeleteSelected"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Delete.gif" />删除选择监测点</asp:LinkButton>&nbsp;&nbsp;
                        <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"><img style="border:0px;vertical-align:middle;" alt="" src="Images/Refresh.gif" />刷新监测点列表</asp:LinkButton>
                    </div>
                </CommandItemTemplate>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="True" EnableDragToSelectRows="True" />
            </ClientSettings>
        </telerik:RadGrid>

</div>
      </td>
  </tr>
</table>

<div id="DataSource">
<%--      <sds:SessionDataSource runat="server" ID="SessionDS"  ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"  ConflictDetection="CompareAllValues"  
        SelectCommand="SELECT &quot;序号&quot;, &quot;作业区&quot;, &quot;监测点代号&quot;, &quot;监测点名称&quot;, &quot;监测点部位&quot;, &quot;建点日期&quot;, &quot;氢探针&quot;, &quot;电阻探针&quot;, &quot;试片失重法&quot;, &quot;介质&quot;, &quot;管线材质&quot;, &quot;管线规格&quot;, &quot;报废日期&quot;, &quot;是否现用&quot;, &quot;备注&quot;, &quot;管道名称&quot;, &quot;场站名称&quot;, &quot;照片ID&quot; FROM &quot;监测点名称表&quot;"
        DeleteCommand="DELETE FROM 监测点名称表 WHERE (监测点代号 = ?)"  >
          <DeleteParameters>
        <asp:Parameter Name="监测点代号"  Type="String" />
        </DeleteParameters>
      </sds:SessionDataSource>--%>
       <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:DBConnectionString %>"
        ProviderName="<%$ ConnectionStrings:DBConnectionString.ProviderName %>"
        SelectCommand="SELECT &quot;序号&quot;, &quot;作业区&quot;, &quot;监测点代号&quot;, &quot;监测点名称&quot;, &quot;监测点部位&quot;, &quot;建点日期&quot;, &quot;氢探针&quot;, &quot;电阻探针&quot;, &quot;试片失重法&quot;, &quot;介质&quot;, &quot;管线材质&quot;, &quot;管线规格&quot;, &quot;报废日期&quot;, &quot;是否现用&quot;, &quot;备注&quot;, &quot;管道名称&quot;, &quot;场站名称&quot;, &quot;照片ID&quot; FROM &quot;监测点名称表&quot;"
        DeleteCommand="DELETE FROM 监测点名称表 WHERE (监测点代号 = :监测点代号)"
       
        UpdateCommand="UPDATE 监测点名称表 SET 序号 = :序号, 作业区 = :作业区, 监测点代号 = :监测点代号, 监测点名称 = :监测点名称, 监测点部位 = :监测点部位, 建点日期 = :建点日期, 氢探针 = :氢探针, 电阻探针 = :电阻探针, 试片失重法 = :试片失重法, 介质 = :介质, 管线材质 = :管线材质, 管线规格 = :管线规格, 报废日期 = :报废日期, 是否现用 = :是否现用, 备注 = :备注, 管道名称 = :管道名称, 场站名称 = :场站名称, 照片ID = :照片ID WHERE (监测点代号 = :监测点代号)">
        <UpdateParameters>
            <asp:Parameter Name="序号" Type="Int32" />
            <asp:Parameter Name="作业区" Type="String" />
            <asp:Parameter Name="监测点代号" Type="String" />
            <asp:Parameter Name="监测点名称" Type="String" />
            <asp:Parameter Name="监测点部位" Type="String" />
            <asp:Parameter Name="建点日期" Type="DateTime" />
            <asp:Parameter Name="氢探针" Type="Int16" />
            <asp:Parameter Name="电阻探针" Type="Int16" />
            <asp:Parameter Name="试片失重法" Type="Int16" />
            <asp:Parameter Name="介质" Type="String" />
            <asp:Parameter Name="管线材质" Type="String" />
            <asp:Parameter Name="管线规格" Type="String" />
            <asp:Parameter Name="报废日期" Type="DateTime" />
            <asp:Parameter Name="是否现用" Type="Int16" />
            <asp:Parameter Name="备注" Type="String" />
            <asp:Parameter Name="管道名称" Type="String" />
            <asp:Parameter Name="场站名称" Type="String" />
            <asp:Parameter Name="照片ID" Type="String" />
        </UpdateParameters>
        <DeleteParameters>
        <asp:Parameter Name="监测点代号"  Type="String" />
        </DeleteParameters>
    </asp:SqlDataSource>
</div>
</asp:Content>

 

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 20 Sep 2010, 10:14 AM
Hello,

You could try by wiring the UpdateCommand event of RadGrid and there overwriting the value passed by RadGrid to the database. The syntax for doing so would be (depending on the checkbox value):
LocalTestDataSource.UpdateParameters["ColumnUniqueName"].DefaultValue = 0;

In case you decide to switch to manual update you can look at the code sample in the Insert/Update/Delete at database level with queries help article.


Greetings,
Tsvetina
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
bin zhang
Top achievements
Rank 1
Answers by
Tsvetina
Telerik team
Share this question
or