当页脚添加按钮时,如何将Gridview OutSide文本框值插入数据库中....请帮助 [英] How to Insert Gridview OutSide Textbox Values into Database, when Footer Add Button Click....Please help

查看:95
本文介绍了当页脚添加按钮时,如何将Gridview OutSide文本框值插入数据库中....请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,



我正在使用asp.net c#,SqlServer 2005.



目前我正在使用gridview页脚文本框,这些工作正常并存储在数据库中。



现在我的要求是:我在gridveiw外面还有2个文本框。

当gridview添加按钮点击页脚时,我想将这些文本框值插入到数据库中。



注意:这两个文本框在gridview之外。

1)TxtStudentRemarks

2)TxtTeacherRemarks



请帮帮我怎么做?



这是我的页脚文本框代码。它的运行正常,但我也想插入外部文本框值,当页脚添加按钮单击。



Hello frnds,

Am working on asp.net c#, SqlServer 2005.

presently am working on gridview footer textboxes, these are working fine and storing in database.

now my requirement is: I also have 2 textboxes outside the gridveiw.
I want to insert including these textbox values into the database when gridview add button clicks from footer.

Note: these 2 textboxes are outside the gridview.
1)TxtStudentRemarks
2)TxtTeacherRemarks

Please help me how to do these ?

This is my code for footer textboxes. its running fine, but also i want to insert outside textboxes values also, when footer add button click.

if (e.CommandName.Equals("AddNew"))
        {

            TextBox TxtFirstName = (TextBox)GvRecords.FooterRow.FindControl("txtFTRFirstName");
            TextBox TxtLastName = (TextBox)GvRecords.FooterRow.FindControl("txtFTRLastName");
            TextBox TxtStudentName = (TextBox)GvRecords.FooterRow.FindControl("txtFTRStudentName");
            TextBox TxRollNo = (TextBox)GvRecords.FooterRow.FindControl("txtFTRRollNo ");
            TextBox TxtResult = (TextBox)GvRecords.FooterRow.FindControl("txtFTRResult");
    
            con.Open();
            
            SqlCommand cmd = new SqlCommand("INSERT into StudentRecords(FirstName,LastName,StudentName,RollNo,Result)VALUES('" + TxtFirstName.Text + "','" + TxtLastName.Text + "','" + TxtStudentName.Text + "','" + TxtRollNo.Text + "', '" + TxtResult.Text + "')", con);
            
            int result = cmd.ExecuteNonQuery();
            con.Close();
            if (result == 1)
            {
                LoadRecords();
                ScriptManager.RegisterStartupScript(this, this.GetType(), "RunCode", "javascript:alert('Added successfully');", true);
            }
           
        }





请帮忙谢谢。



please help thanks.

推荐答案

你可以直接在项命令direclty
u can directly refer those 2 controls out side gridview in item command direclty

中将这两个控件引出到gridview中你希望在同一个(StudentRecords)表中添加该文本框值,然后试试这个:



You want to add that textbox value in same(StudentRecords) table then try this:

SqlCommand cmd = new SqlCommand("INSERT into StudentRecords(FirstName,LastName,StudentName,RollNo,Result,StuRemark,TacherRemark)VALUES('" + TxtFirstName.Text + "','" + TxtLastName.Text + "','" + TxtStudentName.Text + "','" + TxtRollNo.Text + "', '" + TxtResult.Text + "','" + TxtStudentRemark.Text + "')",'" + TxtTeacherRemark.Text + "', con);


这篇关于当页脚添加按钮时,如何将Gridview OutSide文本框值插入数据库中....请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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