DataView具有删除,编辑和创建功能 [英] DataView with deleting,editing and creation

查看:157
本文介绍了DataView具有删除,编辑和创建功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在数据视图中导入数据库中的数据,但超链接删除,编辑和停止不起作用!!!!

i want to import data from database in a dataview but the hyperlink delete,edit and ceate does not work!!!!

推荐答案

我只是给你我的解决方案...我希望它能帮到你..



在网格视图的设计页面中添加



< asp:commandfield showsitbutton =Trueheadertext =Updatexmlns:asp =#unknown>





然后在.cs页面



I just giving you my solution...I hope it will help you..

In design page in grid view add

<asp:commandfield showeditbutton="True" headertext="Update" xmlns:asp="#unknown">


Then in .cs page

protected void gvDeleteCh_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gvDeleteCh.EditIndex = e.NewEditIndex; 
        strinfo = "Select * from tblname"; // your query to data which u want to edit.
        LoadGrid1(strinfo);
    }







protected void gvDeleteCh_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
       // Page.RegisterStartupScript("MY","function msgAlert()");
        try
        {
               try
                {
                    Ocon = new OracleConnection(OracleconnectionString);
                    Ocon.Open();
                    string Name = (((TextBox)gvDeleteCh.Rows[e.RowIndex].Cells[0].Controls[0]).Text.Trim());
                    string UID = (((TextBox)gvDeleteCh.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim());
                    string ID = (((TextBox)gvDeleteCh.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim());
                    string ISACTIVE = (((TextBox)gvDeleteCh.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim());
                    string strSQuery = "update MASTER_TEST set Name='" + Name + "',"
     + "UID='"+UID+"',ID='" + ID + "',ISACTIVE='" + ISACTIVE + "' where UID='"+ UID +"'";
  //   + "select Name,UID,ID,ISACTIVE from MASTER_TEST";
                    Ocmd = new OracleCommand(strSQuery, Ocon);
                    Ocmd.ExecuteNonQuery();
                    lblMsg.Text = "Successfully Updated";
                    TestLog.WriteLog("Updated Successfully " + DateTime.Now);
                    Ocon.Close();
                 }
                catch(Exception ex)
                {
                    lblMsg.Text = ex.Message;
                    TestLog.WriteLog("Error occured while updating the channel " + DateTime.Now);
                
            }
        }
        catch (Exception ex)
        {
            lblMsg.Text = ex.Message;
        }
        gvDeleteCh.EditIndex = -1;
    }
    protected void gvDeleteCh_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
    {
        gvDeleteCh.EditIndex = -1;
        LoadChannels();
    }


这篇关于DataView具有删除,编辑和创建功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆