Click here to Skip to main content
15,922,427 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 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();
    }


once i click edit button in gridview it shows no records
Posted
Updated 25-Jul-13 20:52pm
v2
Comments
Thanks7872 26-Jul-13 2:57am    
Its very bad idea to redirect user to another page,just to edit update the gridview row values where you can do that in same page. Further,its not clear what the question is.
s_rao88 26-Jul-13 3:00am    
well i wasnt using anoher gridview once d page redirects.. but requirement is so now.. let me clear u... i want to edit and update the gridview and once i update it i nee that updated grid row values to be sent as mail.. which is using external button click outside gridview ..

1 solution

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

C#
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();
}


C#
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();
}
 
Share this answer
 
Comments
s_rao88 26-Jul-13 3:03am    
im using 3 layered architecture.. i wnt use data source in code... and editing option is wrking nw.. but when i click on update its sayin (Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900