当前位置:编程学习 > C#/ASP.NET >>

asp.net 插入数据

在repeater中用两个Testbox控件写个插入数据的代码
答案:repeater中放一个<asp:Button ID="editbtn" runat="server" CommandName="insert" Text="插入" />

在repeater的ItemCommand事件中写

switch (e.CommandName)
        {
            case "insert":
                {
                    int editindex = e.Item.ItemIndex;
                    string id = dguser.DataKeys[editindex].ToString();

                    DataRow[] drs = ds.Tables[0].Select("id='" + id + "'");
                    drs[0]["txt1"] = ((TextBox)dguser.Items[editindex].Cells[0].FindControl("textbox1")).Text;
                    drs[0]["txt2"] = ((TextBox)dguser.Items[editindex].Cells[0].FindControl("textbox2")).Text;
                        da.Update(ds);
                        ds.AcceptChanges();
                        dguser.DataSource = ds;
                        dguser.EditItemIndex = -1;
                        dguser.DataBind();
                    }
                    break;
                }
            case "cancel":
                {
                    dguser.DataSource = ds;
                    dguser.EditItemIndex = -1;
                    dguser.DataBind();
                    break;
                }
        }

嗯 是的C# 中string name;这个如果不赋值的话 是会报错的.string name=string.Empty;这样不赋值就不会报错了.


如果帮助到您,请记得采纳为满意答案哈,谢谢!祝您生活愉快! vae.la


上一个:asp判断手机号码
下一个:vbscript html 转换 asp

CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,