(DevExpress2011控件教程)ASPxGridView 范例2 :ASPxGridView 增、删、改及内嵌comboBox

11、 数据编辑

11.1 页面源控制方式

11.1.1 使用sqldatasource 来控制数据的编辑。

SqlDataSource->配置数据源 ->高级 ->生成 insert update  delete语句 ,按确定按钮

 

从源看 sqldatasource生成如下代码

 

<asp:SqlDataSource ID="SqlDataSource1" runat="server"

        ConnectionString="<%$ ConnectionStrings:Connection String %>"

        DeleteCommand="DELETE FROM [com_Dpt1] WHERE [OID] = @OID"

        InsertCommand="INSERT INTO [com_Dpt1] ([dptID], [dptName], [dptFatherID], [dptNo]) VALUES (@dptID, @dptName, @dptFatherID, @dptNo)"

        SelectCommand="SELECT [OID], [dptID], [dptName], [dptFatherID], [dptNo] FROM [com_Dpt1]"

        UpdateCommand="UPDATE [com_Dpt1] SET [dptID] = @dptID, [dptName] = @dptName, [dptFatherID] = @dptFatherID, [dptNo] = @dptNo WHERE [OID] = @OID">

        <DeleteParameters>

            <asp:Parameter Name="OID" Type="Int32" />

        </DeleteParameters>

        <InsertParameters>

            <asp:Parameter Name="dptID" Type="Int32" />

            <asp:Parameter Name="dptName" Type="String" />

            <asp:Parameter Name="dptFatherID" Type="String" />

            <asp:Parameter Name="dptNo" Type="String" />

        </InsertParameters>

        <UpdateParameters>

            <asp:Parameter Name="dptID" Type="Int32" />

            <asp:Parameter Name="dptName" Type="String" />

            <asp:Parameter Name="dptFatherID" Type="String" />

            <asp:Parameter Name="dptNo" Type="String" />

            <asp:Parameter Name="OID" Type="Int32" />

        </UpdateParameters>

    </asp:SqlDataSource>

 

 

11.1.2 代码控制数据的编辑方式

 ASPxGridView添加三个事件 ,分别是RowDeleting , RowInserting ,RowUpdating

protected void ASPxGridView1_RowDeleting(object sender, DevExpress.Web.Data.ASPxDataDeletingEventArgs e)

        {

            string OID = e.Keys["OID"].ToString();//获取关键字

   // 删除操作

        }

 

        protected void ASPxGridView1_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)

        {

            string dptName = e.NewValues["dptName"].ToString();//获取新增的值

            // 新增操作

        }

 

        protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)

        {

            string OID = e.Keys["OID"].ToString();//获取关键字

            string dptName = e.NewValues["dptName"].ToString();//获取更新的值

//更新操作

        }

 

 

12、 ASPxGridView内嵌 Combox

 点击GridView控件,右键 任务-column 插入combobox

在列属性中选择 行为àPropertiesComboBox ->DataSourceId=SqlDataSource1

TextField valueField 值设置为 dptName

数据中设置 FieldName dptName

运行可以见

 

 

posted @ 2011-09-03 11:22  meetweb  阅读(2036)  评论(0编辑  收藏  举报