gridview编辑和更新 [英] gridview editing and updating

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

问题描述

我有一个gridview,并且有超链接列表示更新。单击该页面将重定向到另一个页面,特定行值将显示在另一个网格视图中。并且用户需要编辑1列并进行更新,之后在gridview外面有一个按钮发送或接受,点击它后应该生成一个邮件应该生成它应该采取更新的网格值并将其发送给其他用户和页面应该被重定向到上一页。



gridx的aspx代码



I got a gridview and there is hyperlink column which says update. Upon clicking that page will redirect to another page and particular row values will display in another gridview. and there the user need to edit 1 column and make it update and after that there is a button outside gridview which is send or accept , upon clicking it a mail should get generate it should take updated grid values and send it to he other user and page should get redirected to previous page.

aspx code of gridview

<asp:GridView ID="GridView1" runat="server" AllowSorting="True" 
                     AutoGenerateColumns="false" BackColor="White" BorderColor="#0061C1" 
                     BorderStyle="None" CaptionAlign="Bottom" EmptyDataText="No Records Found" 
                     Font-Names="Verdana" Font-Size="X-Small" ForeColor="#0061C1" Height="70px" 
                     ShowFooter="True" ShowHeaderWhenEmpty="True" OnRowCommand="GridView1_RowCommand" 
                     OnRowDataBound="GridView1_RowDataBound" OnRowEditing="GridView1_RowEditing"
                     onselectedindexchanged="GridView1_SelectedIndexChanged" OnRowUpdating="GridView1_RowUpdating"
                     Width="796px">
                     <columns>
                         <asp:BoundField DataField="LeaveID" Visible="false">
                         <footerstyle backcolor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <itemstyle horizontalalign="Center" verticalalign="Middle" width="10px" />
                         
                         <asp:TemplateField HeaderText="Applied By">
                         <itemtemplate>
                         <asp:Label 
                            ID="LoggedInUser" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="24px" Text='<%# Eval("LoggedInUser")%>' Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                    <asp:TemplateField HeaderText="Begin Date">
                    <itemtemplate>
                    <asp:Label 
                            ID="BeginDate" runat="server" DataFormatString="{0:dd/MM/yyyy}" 
                            Font-Names="Verdana" Text='<%# Eval("BeginDate","{0:dd/MM/yyyy}")%>' Font-Size="X-Small" Height="20px" 
                             Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                    <asp:TemplateField HeaderText="End Date">
                    <itemtemplate>
                    <asp:Label 
                            ID="EndDate" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("EndDate","{0:dd/MM/yyyy}")%>'  Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                    <asp:TemplateField HeaderText="Num of Days">
                    <itemtemplate>
                    <asp:Label 
                            ID="NumofDays" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("NumofDays")%>' Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                    <asp:TemplateField HeaderText="Type of Leave ">
                    <itemtemplate>
                    <asp:Label 
                            ID="LeaveType" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            Height="20px" Text='<%# Eval("TypeofLeave")%>'  Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                    <asp:TemplateField HeaderText="Status">
                    <itemtemplate>
                    <asp:Label 
                            ID="Status" runat="server" Font-Names="Verdana" Font-Size="X-Small" 
                            ForeColor="Black" Height="20px" Text='<%# Eval("Status")%>'  Width="100px">
                    </itemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                        <asp:TemplateField  HeaderText="Reason for Reject">
                        <itemtemplate>
                        <asp:Label ID="RejectReason" 
                            runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" 
                            Height="20px" Text='<%# Eval("RejectReason")%>' Enabled="true" Visible="true" Width="100px">
                    </itemtemplate>
                    <edititemtemplate>
                    <asp:TextBox ID="TxtRejectReason" 
                            runat="server" Font-Names="Verdana" Font-Size="X-Small" ForeColor="Black" 
                            Height="20px" Text='<%# Eval("RejectReason")%>' Enabled="true" Visible="true" Width="100px">
                    </edititemtemplate>
                    <footerstyle backcolor="#0061C1" />
                    <HeaderStyle BackColor="#0061C1" ForeColor="White"></HeaderStyle>
                    <itemstyle horizontalalign="Center" verticalalign="Middle"></itemstyle>
                    
                         <asp:BoundField DataField="LogdInUser" Visible="false" >
                         <footerstyle backcolor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <itemstyle horizontalalign="Center" verticalalign="Middle" width="100px" />
                         
                         <asp:BoundField DataField="Manager" Visible="false" >
                         <footerstyle backcolor="#0061C1" />
                         <HeaderStyle BackColor="#0061C1" ForeColor="White" HorizontalAlign="Center" 
                             VerticalAlign="Middle" />
                         <itemstyle horizontalalign="Center" verticalalign="Middle" width="100px" />
                         
                         <asp:CommandField ShowEditButton="true"  ButtonType="Button"  EditText="Edit">
                <controlstyle width="50" />
            
                     </columns>



i需要编辑RejectReason专栏。



cs页




i need to edit RejectReason Column.

cs page

<pre lang="c#">protected void Page_Load(object sender, EventArgs e)
    {
        MTMSDTO objc = new MTMSDTO();
        if (!IsPostBack)
        {
            int LeaveID = 0;
            int.TryParse(Request.QueryString["LeaveID"], out LeaveID);
            objc.LeaveID = LeaveID;
            objc.RejectReason = TxtRejectReason.Text;
            DataSet lapp = obj.GetLeaveApproved(objc);
            DataView LApp = new DataView();
            LApp.Table = lapp.Tables[0];
            GridView1.DataSource = LApp;
            GridView1.DataBind();

        }
    }

    protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
    {
        GridView1.EditIndex = e.NewEditIndex;
        GridView1.DataBind();
    }

    protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        int LeaveID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value.ToString());

        TextBox TxtRejectReason = (TextBox)GridView1.Rows[e.RowIndex].FindControl("TxtRejectReason");

        GridView1.EditIndex = -1;
        GridView1.DataBind();
    }





一旦我点击gridview中的编辑按钮就显示没有记录



once i click edit button in gridview it shows no records

推荐答案

你可以调试它并将一些有用的调试消息粘贴给我吗?



Could you debug it and paste some useful debug messages to me ?

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;


    //your problem maybe is here .
    //you need query data from the database and bind again 
    //like :
    //Bind();

    GridView1.DataBind();
}







void Bind()
{
       SqlDataAdapter da = new SqlDataAdapter("select * from emp", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "emp");
        GridView1.DataSource = ds.Tables[0];
        GridView1.DataBind();
        conn.Close();
}


这篇关于gridview编辑和更新的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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