本文介绍了请帮帮我!!使用存储过程的可编辑gridview的简单示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有朋友

到我的m / c测试,我必须创建一个简单的程序,通过使用存储过程创建可编辑的网格视图。请尽快回复这对我来说非常重要..... !!请回复源代码.....非常感谢

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

推荐答案

<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>







代码背后是



protected void GRVManual_RowEditing(对象发送者,GridViewEditEventArgs e)

{

GRVManual.EditIndex = e.NewEditIndex;

Session [TempRowIndex] = GRVManual.EditIndex;



GRVManual.DataSource = Session [Dt_StudentDetails];

GRVManual.DataBind();

}



protected void GRV Manual_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(反馈,反馈);







Se ssion [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(对象发送者,GridViewCommandEventArgs e)

{



}



protected void GRVManual_RowDeleting(object sender,GridViewDeleteEventArgs e)

{

Dt_StudentDetails =(DataTable)(会话[Dt_StudentDetails]);

GRVManual.EditIndex = e.RowIndex;

Dt_StudentDetails.Rows [GRVManual.EditIndex] .Delete();







GRVManual.EditIndex = - 1;

GRVManual.DataSource = Dt_StudentDetails;

GRVManual.DataBind();



}

}




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();

}
}


这篇关于请帮帮我!!使用存储过程的可编辑gridview的简单示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 12:24