Radgrid的增删改

protected void RadGrid4_UpdateCommand(object source,

                                          GridCommandEventArgs e)

    {

        var editedItem = e.Item as GridEditableItem ;

        // 获取编辑框里的 taskid

string taskId = editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["taskId" ].ToString();

        // 获取编辑框里的控件( html 里可以用 例子 1 和例子二的模式

string taskName = ((TextBox ) editedItem.FindControl("TextBox1" )).Text;

        string description = ((TextBox ) editedItem.FindControl("TextBox2" )).Text;

        string standardtime = ((TextBox ) editedItem.FindControl("TextBox3" )).Text;

 

 

        string updatesql = "update Tasks set taskName='" + taskName + "',description='" + description +

                           "',expectedTaskLength='" + standardtime + "' where taskId='" + taskId +

                           "' and nonproductionTask='false'" ;

        DbConnector .runSql(updatesql);

  // 关闭编辑窗口      

RadGrid4.MasterTableView.Items[editedItem.ItemIndex].Edit = false ;

    }

 

 

    protected void RadGrid4_DeleteCommand(object source, GridCommandEventArgs e)

    {

        string ID = e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["taskId" ].ToString();

        string deletesql = "delete from Tasks where taskId='" + ID + "'" ;

        DbConnector .runSql(deletesql);

    }

 

    protected void RadGrid4_InsertCommand(object source, GridCommandEventArgs e)

    {

        var insertedItem = (GridEditFormInsertItem ) e.Item;

        string taskName = ((TextBox ) insertedItem.FindControl("TextBox1" )).Text.Trim();

        string description = ((TextBox ) insertedItem.FindControl("TextBox2" )).Text.Trim();

        string standardtime = ((TextBox ) insertedItem.FindControl("TextBox3" )).Text.Trim();

        string insertQuery =

            "INSERT into  Tasks(taskName,description,expectedTaskLength,nonproductionTask,workTask) values('" +

            taskName + "','" + description + "','" + standardtime + "','false','false')" ;

        DbConnector .runSql(insertQuery);

// 这里是关闭 insert 的窗口

        e.Canceled = true ;

        e.Item.OwnerTableView.IsItemInserted = false ;

        RadGrid4.Rebind();

    }

 

 

 

 

 

例子 1:

    < EditFormSettings EditFormType ="Template">// 这里是设置 editfrom 类型 ,自定义模板

                            < EditColumn UniqueName ="EditCommandColumn1">

                            </ EditColumn >

                            < FormTemplate >

                                taskName:< asp : TextBox ID ="TextBox1" runat ="server"

                                    Text =' <% # bind ("taskName")%> '></ asp : TextBox >

                                < br />

                                description:< asp : TextBox ID ="TextBox2" runat ="server"

                                    Text =' <% # bind ("description")%> '></ asp : TextBox >

                                < br />

                                standardTime:< asp : TextBox ID ="TextBox3" runat ="server"

                                    Text =' <% # bind ("expectedTaskLength")%> '></ asp : TextBox >< asp : RegularExpressionValidator ID ="reg1" runat ="server" ControlToValidate ="TextBox3" ValidationExpression ="^[0-9]*$" ErrorMessage ="Please input the number."></ asp : RegularExpressionValidator >

                                < br />

                                < asp : Button ID ="btnUpdate0" runat ="server" CommandName =' <% # (Container is GridEditFormInsertItem)

                                        ? "PerformInsert"

                                        : "Update"%> ' Text =' <% # (Container is GridEditFormInsertItem) ? "Insert" : "Update"%> ' />

                                 &nbsp;

                                < asp : Button ID ="btnCancel0" runat ="server" CausesValidation ="False"

                                    CommandName ="Cancel" Text ="Cancel" / >

                            </ FormTemplate >

                         </ EditFormSettings >

 

 

例子 2

< Columns >

                            < telerik : GridBoundColumn DataField ="taskId" DataType ="System.Int32"

                                HeaderText ="taskId" ReadOnly ="True" SortExpression ="taskId" UniqueName ="taskId"

                                Visible ="False">

                            </ telerik : GridBoundColumn >

                            < telerik : GridBoundColumn DataField ="taskName" HeaderText ="taskName"

                                SortExpression ="taskName" UniqueName ="taskName" ReadOnly =true>

                            </ telerik : GridBoundColumn >

                            < telerik : GridBoundColumn DataField ="description" HeaderText ="description"

                                SortExpression ="description" UniqueName ="description" ReadOnly =true>

                            </ telerik : GridBoundColumn >

                         

                            < telerik : GridTemplateColumn HeaderText ="Assign">

                                < ItemTemplate >// 这里是自己设置 gridtable 的列

                                   < asp : CheckBox ID ="chb" runat ="server" Checked =' <% # Convert.ToBoolean(Eval("assign")) %> ' OnCheckedChanged ="chb_CheckedChanged" AutoPostBack ="true"   />   

                                </ ItemTemplate >

                                < EditItemTemplate >// 这里是设置 editfrom 里的

                                    < asp : CheckBox ID ="chbItemEdt" runat ="server" Checked =' <% # Convert.ToBoolean(Eval("assign")) %> ' />   

                                </ EditItemTemplate >

                            </ telerik : GridTemplateColumn >

                        </ Columns >

 

 

 


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值