本文介绍了想在gridview底部添加行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 此代码用于在gridview中添加新行。当我在文本框中写入值并按下按钮然后它将在gridview中添加一行。按下按钮行添加但是在表格的顶部我希望它在结束了... 告诉我该怎么做 private void AddNewRecord(string ID,string name,string qty,string type,string desc,string model,string sn,string tag,string cty,string node,string ip,string fip,string pro,string ram,string hd,string rmana,bool isUpdate) { SqlConnection connection = new SqlConnection(connstring); string sqlStatement = string.Empty; if(!isUpdate) { sqlStatement =INSERT INTO [''ISB VAS Nodes $' ']+ (ID,RackName,QTY,Type,[Desc],Model,SN,AssetTag,City,NodeName,IPAddress,FloatIP,处理器,RAM,HardDisks,RAIDManager)+ VALUES(@I d,@ RackName,@数量,@类型,@ DESC,@模型,@ SN,@ ASSETTAG,@城市,@节点名,@的IPAddress,@ FloatIP,@处理器,@ RAM,@硬碟,@ RAIDManager); } 其他 { Label2.Text =错误; } 试试 { connection.Open(); SqlCommand cmd = new SqlCommand(sqlStatement,connection ); cmd.Parameters.AddWithValue(@ ID,ID); cmd.Parameters.AddWithValue(@ RackName,Name); cmd.Parameters.AddWithValue(@ qty,qty); cmd.Parameters.AddWithValue(@ type,type); cmd。 Parameters.AddWithValue(@ desc,desc); cmd.Parameters.AddWithValue(@ model,model); cmd.Parameters.AddWithValue(@ sn,sn); cmd.Parameters.AddWithValue(@ AssetTag,tag); cmd.Paramet ers.AddWithValue(@ city,cty); cmd.Parameters.AddWithValue(@ NodeName,node); cmd.Parameters.AddWithValue(@ IPAddress,ip); cmd.Parameters.AddWithValue(@ FloatIP,fip); cmd.Parameters.AddWithValue(@ Processors,pro); cmd.Parameters.AddWithValue(@ ram,ram); cmd.Parameters.AddWithValue(@ HardDisks,hd); cmd.Parameters.AddWithValue(@ RAIDManager,rmana); cmd.CommandType = CommandType.Text; cmd。 ExecuteNonQuery(); } catch(System.Data.SqlClient.SqlException ex) { string msg =插入/更新错误:; msg + = ex.Message; 抛出新的异常(msg); } 终于 { connection.Close(); } } protected void Button2_Click(object sender,EventArgs e) { AddNewRecord(TextBox3.Text,TextBox4.Text,TextBox5.Text,TextBox6.Text,TextBox7.Text,TextBox8.Text,TextBox9.Text,TextBox10.Text ,TextBox11.Text,TextBox11.Text,TextBox12.Text,TextBox13.Text,TextBox14.Text,TextBox15.Text,TextBox16.Text,TextBox17.Text,false); //重新绑定GridView到反映所做的更改 binddata(); }this code is for adding new row in gridview.when i write values in text box and press button then it will add a row in gridview.on pressing button row is added but at the top of the table i want it at the end of the table...tell me how to do thatprivate void AddNewRecord(string ID, string Name, string qty, string type, string desc, string model, string sn, string tag, string cty, string node, string ip, string fip, string pro, string ram, string hd, string rmana, bool isUpdate) { SqlConnection connection = new SqlConnection(connstring); string sqlStatement = string.Empty; if (!isUpdate) { sqlStatement = "INSERT INTO [''ISB VAS Nodes$'']" +"(ID,RackName,QTY,Type,[Desc],Model,SN,AssetTag,City,NodeName,IPAddress,FloatIP,Processors,RAM,HardDisks,RAIDManager)" +"VALUES (@ID,@RackName,@qty,@type,@desc,@model,@sn,@AssetTag,@city,@NodeName,@IPAddress,@FloatIP,@Processors,@ram,@HardDisks,@RAIDManager)"; } else { Label2.Text = "Error"; } try { connection.Open(); SqlCommand cmd = new SqlCommand(sqlStatement, connection); cmd.Parameters.AddWithValue("@ID", ID); cmd.Parameters.AddWithValue("@RackName", Name); cmd.Parameters.AddWithValue("@qty", qty); cmd.Parameters.AddWithValue("@type", type); cmd.Parameters.AddWithValue("@desc", desc); cmd.Parameters.AddWithValue("@model", model); cmd.Parameters.AddWithValue("@sn", sn); cmd.Parameters.AddWithValue("@AssetTag", tag); cmd.Parameters.AddWithValue("@city", cty); cmd.Parameters.AddWithValue("@NodeName", node); cmd.Parameters.AddWithValue("@IPAddress", ip); cmd.Parameters.AddWithValue("@FloatIP", fip); cmd.Parameters.AddWithValue("@Processors", pro); cmd.Parameters.AddWithValue("@ram", ram); cmd.Parameters.AddWithValue("@HardDisks", hd); cmd.Parameters.AddWithValue("@RAIDManager", rmana); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert/Update Error:"; msg += ex.Message; throw new Exception(msg); } finally { connection.Close(); } } protected void Button2_Click(object sender, EventArgs e) { AddNewRecord(TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text,TextBox11.Text,TextBox11.Text,TextBox12.Text,TextBox13.Text,TextBox14.Text,TextBox15.Text,TextBox16.Text,TextBox17.Text, false); //Re Bind GridView to reflect changes made binddata(); }推荐答案'']+ (ID,RackName,QTY,Type,[Desc],Model,SN,AssetTag,City,NodeName,IPAddress,FloatIP,处理器,RAM,HardDisks,RAIDManager)+ VALUES(@ ID,@ RackName,@ qty,@ type,@ desc,@ model,@ sn,@ AssetTag,@ city,@ NodeName,@ IPAddress,@ FloatIP,@ Processors,@ ram,@ HardDisks,@ RAIDManager ); } else { Label2.Text =错误; } 尝试 { connection.Open(); SqlCommand cmd = new SqlCommand(sqlStatement,connection); cmd.Parameters.AddWithValue(@ ID,ID); cmd。 Parameters.AddWithValue(@ RackName,Name); cmd.Parameters.AddWithValue(@ qty,qty); cmd.Parameters.AddWithValue(@输入,类型; cmd.Parameters.AddWithValue(@ desc,desc); cmd.Parameters.AddWithValue(@ model,model); cmd.Parameters.AddWithValue(@ sn,sn); cmd.Parameters.AddWithValue(@ AssetTag,tag); cmd.Parameters.AddWithValue(@ city,cty); cmd.Parameters.AddWithValue(@ NodeName,node); cmd.Parameters。 AddWithValue(@ IPAddress,ip); cmd.Parame ters.AddWithValue(@ FloatIP,fip); cmd.Parameters.AddWithValue(@ Processors,pro); cmd.Parameters.AddWithValue(@ ram,ram); cmd.Parameters.AddWithValue(@ HardDisks,hd); cmd.Parameters.AddWithValue(@ RAIDManager,rmana); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch(System.Data.SqlClient.SqlException ex) { string msg =插入/更新错误:; msg + = ex.Message; 抛出新的异常(msg); } 终于 { connection.Close(); } } protected void Button2_Click(object sender,EventArgs e) { AddNewRecord (TextBox3.Text,TextBox4.Text,TextBox5.Text,TextBox6.Text,TextBox7.Text,TextBox8.Text,TextBox9.Text,TextBox10.Text,TextBox11.Text,TextBox11.Text,TextBox12.Text,TextBox13.Text,TextBox14 .Text,TextBox15.Text,TextBox16.Text,TextBox17.Text,false); //重新绑定GridView以反映所做的更改 binddata(); }'']" +"(ID,RackName,QTY,Type,[Desc],Model,SN,AssetTag,City,NodeName,IPAddress,FloatIP,Processors,RAM,HardDisks,RAIDManager)" +"VALUES (@ID,@RackName,@qty,@type,@desc,@model,@sn,@AssetTag,@city,@NodeName,@IPAddress,@FloatIP,@Processors,@ram,@HardDisks,@RAIDManager)"; } else { Label2.Text = "Error"; } try { connection.Open(); SqlCommand cmd = new SqlCommand(sqlStatement, connection); cmd.Parameters.AddWithValue("@ID", ID); cmd.Parameters.AddWithValue("@RackName", Name); cmd.Parameters.AddWithValue("@qty", qty); cmd.Parameters.AddWithValue("@type", type); cmd.Parameters.AddWithValue("@desc", desc); cmd.Parameters.AddWithValue("@model", model); cmd.Parameters.AddWithValue("@sn", sn); cmd.Parameters.AddWithValue("@AssetTag", tag); cmd.Parameters.AddWithValue("@city", cty); cmd.Parameters.AddWithValue("@NodeName", node); cmd.Parameters.AddWithValue("@IPAddress", ip); cmd.Parameters.AddWithValue("@FloatIP", fip); cmd.Parameters.AddWithValue("@Processors", pro); cmd.Parameters.AddWithValue("@ram", ram); cmd.Parameters.AddWithValue("@HardDisks", hd); cmd.Parameters.AddWithValue("@RAIDManager", rmana); cmd.CommandType = CommandType.Text; cmd.ExecuteNonQuery(); } catch (System.Data.SqlClient.SqlException ex) { string msg = "Insert/Update Error:"; msg += ex.Message; throw new Exception(msg); } finally { connection.Close(); } } protected void Button2_Click(object sender, EventArgs e) { AddNewRecord(TextBox3.Text, TextBox4.Text, TextBox5.Text, TextBox6.Text, TextBox7.Text, TextBox8.Text, TextBox9.Text, TextBox10.Text,TextBox11.Text,TextBox11.Text,TextBox12.Text,TextBox13.Text,TextBox14.Text,TextBox15.Text,TextBox16.Text,TextBox17.Text, false); //Re Bind GridView to reflect changes made binddata(); }为什么在将数据绑定到gridview时不要在ur select语句中应用order by子句 exa。why dont apply order by clause on ur select statement at time of bind data to gridviewexa."select * from tablename by id asc" 这篇关于想在gridview底部添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-14 10:43