Click here to Skip to main content
15,921,884 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Dear All my Friends
to day my m/c test in which i have to create a simple program for creating a editable grid view by using stored procedure. please reply soon it is so important for me.....!! please reply source code.....thanks a lot
Posted
Updated 9-Apr-13 20:15pm
v2

1 solution

XML
<asp:GridView ID="GRVManual" AutoGenerateColumns="False" runat="server" OnRowEditing="GRVManual_RowEditing"
        OnRowCancelingEdit="GRVManual_RowCancelingEdit" OnRowCommand="GRVManual_RowCommand"
        OnRowUpdating="GRVManual_RowUpdating" OnRowDeleting="GRVManual_RowDeleting">
        <Columns>
            <asp:TemplateField HeaderText="StudentName">
                <ItemTemplate>
                    <%#Eval("StudentName")%></ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtStudentName" runat="server" Text='<%#Eval("StudentName")%>' />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="ContactNo">
                <ItemTemplate>
                    <%#Eval("ContactNo")%></ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtStudentContactNo" Text='<%#Eval("ContactNo")%>' runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Email">
                <ItemTemplate>
                    <%#Eval("Email")%></ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtStudentEmail" Text='<%#Eval("Email")%>' runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Redeemed">
                <ItemTemplate>
                    <%#Eval("Redeemed")%></ItemTemplate>
                <EditItemTemplate>
                    <asp:DropDownList ID="DDLRedeemed" runat="server" SelectedValue='<%#Eval("Redeemed")%>'>
                        <asp:ListItem Value="Yes" Text="Yes"> </asp:ListItem>
                        <asp:ListItem Value="No" Text="No"></asp:ListItem>
                    </asp:DropDownList>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField HeaderText="Feedback">
                <ItemTemplate>
                    <%#Eval("Feedback")%></ItemTemplate>
                <EditItemTemplate>
                    <asp:TextBox ID="txtFeedback" Text='<%#Eval("Feedback")%>' runat="server" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="btnedit" runat="server" CommandName="Edit" Text="Edit" />
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:LinkButton ID="btnupdate" runat="server" CommandName="Update" Text="Update" />
                    <asp:LinkButton ID="btncancel" runat="server" CommandName="Cancel" Text="Cancel" />
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:LinkButton ID="btndelete" runat="server" CommandName="Delete" Text="Delete" />
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>



Code Behind is

protected void GRVManual_RowEditing(object sender, GridViewEditEventArgs e)
{
GRVManual.EditIndex = e.NewEditIndex;
Session["TempRowIndex"] = GRVManual.EditIndex;

GRVManual.DataSource = Session["Dt_StudentDetails"];
GRVManual.DataBind();
}

protected void GRVManual_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int indexno = int.Parse(Session["TempRowIndex"].ToString());
GridViewRow row = GRVManual.Rows[indexno];
TextBox txtStudentName = (TextBox)row.FindControl("txtStudentName");
TextBox txtStudentContactNo = (TextBox)row.FindControl("txtStudentContactNo");
TextBox txtStudentEmail = (TextBox)row.FindControl("txtStudentEmail");
DropDownList txtRedeemed = (DropDownList)row.FindControl("DDLRedeemed");
TextBox txtFeedback = (TextBox)row.FindControl("txtFeedback");


UpdateRecord(txtStudentName.Text, txtStudentContactNo.Text, txtStudentEmail.Text, txtRedeemed.Text,txtFeedback.Text,indexno);
GRVManual.EditIndex = -1;
GRVManual.DataSource = Dt_StudentDetails;
GRVManual.DataBind();

}

private void UpdateRecord(string StudentName, string ContactNo, string Email, string Redeemed, string Feedback,int indexno)
{
Dt_StudentDetails = (DataTable)(Session["Dt_StudentDetails"]);
DataRow Dr = Dt_StudentDetails.NewRow();
Dt_StudentDetails.ImportRow(Dr);

Dt_StudentDetails.Rows[indexno].SetField("StudentName", StudentName);
Dt_StudentDetails.Rows[indexno].SetField("ContactNo", ContactNo);
Dt_StudentDetails.Rows[indexno].SetField("Email", Email);
Dt_StudentDetails.Rows[indexno].SetField("Redeemed", Redeemed);
Dt_StudentDetails.Rows[indexno].SetField("Feedback", Feedback);



Session["Dt_StudentDetails"] = Dt_StudentDetails;
GRVManual.DataSource = Dt_StudentDetails;
GRVManual.DataBind();


}

protected void GRVManual_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GRVManual.EditIndex = -1;
GRVManual.DataSource = Dt_StudentDetails;
GRVManual.DataBind();
}

protected void GRVManual_RowCommand(object sender, GridViewCommandEventArgs e)
{

}

protected void GRVManual_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Dt_StudentDetails = (DataTable)(Session["Dt_StudentDetails"]);
GRVManual.EditIndex = e.RowIndex;
Dt_StudentDetails.Rows[GRVManual.EditIndex].Delete();



GRVManual.EditIndex = -1;
GRVManual.DataSource = Dt_StudentDetails;
GRVManual.DataBind();

}
}
 
Share this answer
 
v2
Comments
Ramya SV 10-Apr-13 2:18am    
Please let me know if this is helpful or not.

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