I have a gridview that has some rows in it.and some of gridview's row was merged with colspan. now I want to transfer the selected row of my first gridview to the second gridview.
for example, if 3rows merged I want to transfer that 3 rows, to the second gridview.
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnDataBound="OnDataBound" >
<Columns>
<asp:BoundField DataField="TRoom" HeaderText="نام اتاق" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="DayWeek" HeaderText="روز هفته" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="ET" HeaderText="ساعت پایان کلاس" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="ST" HeaderText="ساعت شروع کلاس" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="LNProfessor" HeaderText="نام خانوادگی استاد" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="NProfessor" HeaderText="نام استاد" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="Code" HeaderText="کد درس" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="TLesson" HeaderText="نام درس" HeaderStyle-CssClass="header-center" />
<asp:BoundField DataField="CourseId" HeaderText="آی دی" HeaderStyle-CssClass="header-center" />
</Columns>
<HeaderStyle BackColor="#3AC0F2" ForeColor="White"></HeaderStyle>
</asp:GridView>
the code that merges rows with colspan:
protected void GridView1_DataBound(object sender, EventArgs e)
{
for (int i = GridView1.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = GridView1.Rows[i];
GridViewRow previousRow = GridView1.Rows[i - 1];
CheckBox chk = row.FindControl("chkSelect") as CheckBox;
int count = row.Cells.Count - 1;
for (int j = 8; j >5; j--)
{
if (row.Cells[j].Text == previousRow.Cells[j].Text)
{
if (previousRow.Cells[j].RowSpan == 0)
{
if (row.Cells[j].RowSpan == 0)
{
previousRow.Cells[j].RowSpan += 2;
previousRow.Cells[count].RowSpan = 2;
}
else
{
previousRow.Cells[j].RowSpan = row.Cells[j].RowSpan + 1;
previousRow.Cells[count].RowSpan = row.Cells[j].RowSpan + 1;
}
chk.Visible = false;
row.Cells[j + 1].Visible = false;
row.Cells[j].Visible = false;
}
}
}
}
the code for getting selected record to transfer:
protected void GetSelectedRecords(object sender, EventArgs e)
{
DataTable dt1 = new DataTable();
int s = 0;
for (int i = GridView1.Rows.Count - 1; i > 0; i--)
{
GridViewRow row = GridView1.Rows[i];
GridViewRow previousRow = GridView1.Rows[i - 1];
CheckBox chk = row.FindControl("chkSelect") as CheckBox;
int count = row.Cells.Count - 1;
for (int j = 8; j > 5; j--)
{
if (row.Cells[j].Text == previousRow.Cells[j].Text)
{
s++;
}
}
foreach (GridViewRow row1 in GridView1.Rows)
{
for (int i1 = 0; i1 < s; i1++)
{
CheckBox chkRow = (row.Cells[i1].FindControl("chkselect") as CheckBox);
if (chkRow.Checked)
{
string TRoom = row.Cells[0].Text;
string DayWeek = row.Cells[1].Text;
string StartTime = row.Cells[2].Text;
string EndTime = row.Cells[3].Text;
string Family = row.Cells[4].Text;
string Name = row.Cells[5].Text;
string LessonCode = row.Cells[6].Text;
string LessonName = row.Cells[7].Text;
string CourseId = row.Cells[8].Text;
dt1.Rows.Add(TRoom, DayWeek, EndTime, StartTime, Family, Name, LessonCode, LessonName, CourseId);
}
}
}
gvSelected.DataSource = dt1;
gvSelected.DataBind();
}
}
I tried it in above code but it doesn't work correctly. how can I do that?!