如何在包含控件的gridview行之间插入空行 [英] How to insert blank row between gridview rows that contains controls

查看:96
本文介绍了如何在包含控件的gridview行之间插入空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我试图在gridview行之间添加空行。现有行也包含文本框控件。在初始获取请求时,页面在相应的文本框中以适当的值正确呈现。但是在gridview外部的按钮单击上,插入的新行之后第一个网格行的文本框的值将移动到文本框控件中的新行。插入新行时,没有文本框控件。



Hi All,

I am trying to add blank rows in between gridview rows. The existing rows contains textbox controls as well. On initial get request the page is rendered correctly with proper value in respective textboxes. But on button click outside the gridview, the value of textbox of first grid row after the inserted new row is getting shifted to the new row in a textbox control. While inserting new row, there was no textbox control.

public void AddNewRow(object sender, GridViewRowEventArgs e)
        {
            GridView GridView1 = (GridView)sender;
            GridViewRow NewTotalRow = new GridViewRow(0, 0, DataControlRowType.EmptyDataRow, DataControlRowState.Insert);
            NewTotalRow.Font.Bold = true;
            NewTotalRow.BackColor = System.Drawing.Color.Blue;
            TableCell HeaderCell = new TableCell();
            HeaderCell.Height = 25;
            HeaderCell.HorizontalAlign = HorizontalAlign.Center;
            HeaderCell.ColumnSpan = 10;
            HeaderCell.ForeColor = System.Drawing.Color.White;
            HeaderCell.Text = "1st Level Subordinates";
            NewTotalRow.Cells.Add(HeaderCell);
            GridView1.Controls[0].Controls.AddAt(e.Row.RowIndex + rowIndex, NewTotalRow);
            rowIndex++;
        }

 protected void cmdBtn_saveSubmit_Click(object sender, CommandEventArgs e)
        { foreach (GridViewRow gvRow in grid_score.Rows)
                {
                    if (gvRow.RowType != DataControlRowType.EmptyDataRow)
                    {
                     TextBox txtscore = gvRow.Cells[7].FindControl("txtbox") as TextBox;
                    string score = txtscore.Text.ToString();
                     if (score =="")
                      {                                    System.Web.UI.ScriptManager.RegisterStartupScript(this, GetType(), "displayalertmessage", "alert('alert');", true);
                                        return;
                      }
                    }
                 }
        }





我的尝试:



return语句,当页面重新出现时,emptydatarow的格式被删除。此外,当检查emptydatarow时,它显示为正常的数据行,并且正好在emptydatarow下面的文本框的值被转移到空行中的文本框。



What I have tried:

here after return statement, when the page reappears, the formatting of emptydatarow is getting removed. Also when checking emptydatarow, it is showing as normal datarow and value of textbox just below emptydatarow is getting shifted to textbox in empty row.

推荐答案

DataTable dt = new DataTable();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            if(/* add ur condition wer control exist or not*/)
            {
            DataRow dr = dt.NewRow();
            dr[0] = 0;
            dt.Rows.InsertAt(dr, i);
            }
        }


这篇关于如何在包含控件的gridview行之间插入空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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