How to move GridView multiple rows up and down? - c#

I have a devexpress gridview bound to a datatable, right now I move one row up and down, by following some topic post on this blog.
What I need is to move multiple rows up and down.
for example on the button click event I have this
private void btnMoveMotor_Up_Click(object sender, EventArgs e)
{
GridView view = gridView_Motores;
view.GridControl.Focus();
int index = view.FocusedRowHandle;
if (index <= 0) return;
DataRow row1 = view.GetDataRow(index);
DataRow row2 = view.GetDataRow(index - 1);
object idcentg = row1[Codigo];
object idbatg = row1[batg];
object idunig = row1[unig];
object pot_cal = row1[potCalculada];
object pot_trab = row1[potTrabajo];
object idcentg1 = row2[Codigo];
object idbatg1 = row2[batg];
object idunig1 = row2[unig];
object pot_cal1 = row2[potCalculada];
object pot_trab1 = row2[potTrabajo];
row1[Codigo] = idcentg1;
row1[batg] = idbatg1;
row1[unig] = idunig1;
row1[potCalculada] = pot_cal1;
row1[potTrabajo] = pot_trab1;
row2[Codigo] = idcentg;
row2[batg] = idbatg;
row2[unig] = idunig;
row2[potCalculada] = pot_cal;
row2[potTrabajo] = pot_trab;
view.FocusedRowHandle = index - 1;
btnAplicar.Enabled = true;
btnAplicarOrdenMotores.Enabled = true;
}
Thanks!!!

I don't know how you actually move your row since you didn't post this solution, but maybe you just looking for following options to set
gridView1.OptionsSelection.MultiSelect = true;
gridView1.OptionsSelection.MultiSelectMode = DevExpress.XtraGrid.Views.Grid.GridMultiSelectMode.RowSelect;
and your code will work with multiple rows just like for one row.

if (view.SelectedRowsCount == 1)
{
// I do what I post in my question
}
if(view.SelectedRowsCount > 1)
{
int[] pos = new int[view.SelectedRowsCount];
pos = view.GetSelectedRows();//save into an array the selected rows handle
int lastHandle = pos.Last();
DataTable tableAux = new DataTable();
tableAux.Columns.Add("idcentg", typeof(string));
tableAux.Columns.Add("idbatg", typeof(int));
tableAux.Columns.Add("idunig", typeof(int));
tableAux.Columns.Add("potCalculada", typeof(decimal));
tableAux.Columns.Add("potTrabajo", typeof(decimal));
tableAux.Columns.Add("orden", typeof(int));
tableAux.Columns.Add("capinsg", typeof(decimal));
for (int i = 0; i < gridView_Motores.DataRowCount; i++)
{
tableAux.Rows.Add(gridView_Motores.GetRowCellValue(i,"idcentg"), gridView_Motores.GetRowCellValue(i, "idbatg"),
gridView_Motores.GetRowCellValue(i, "idunig"), gridView_Motores.GetRowCellValue(i, "potCalculada"),
gridView_Motores.GetRowCellValue(i, "potTrabajo"), gridView_Motores.GetRowCellValue(i, "orden"),
gridView_Motores.GetRowCellValue(i, "capinsg"));
}
int tag = 1;
int cont = 1;
for (int i = 0; i < pos.Length; i++)
{
if (tag == 1)
{
DataRow selectedRow = tableAux.Rows[pos[i]];
DataRow newRow = tableAux.NewRow();
newRow.ItemArray = selectedRow.ItemArray;
tableAux.Rows.Remove(selectedRow);
tableAux.Rows.InsertAt(newRow, lastHandle + 1);
}
else
{
DataRow selectedRow = tableAux.Rows[pos[i] - cont];
DataRow newRow = tableAux.NewRow();
newRow.ItemArray = selectedRow.ItemArray;
tableAux.Rows.Remove(selectedRow);
tableAux.Rows.InsertAt(newRow, lastHandle + 1);
cont++;
}
tag++;
}
int orden = 1;
foreach (DataRow row in tableAux.Rows)
{
row["orden"] = orden;
orden++;
}
grid_OrdenMotores.DataSource = null;
grid_OrdenMotores.DataSource = tableAux;
}

Related

C# Node Collection using HTMLAgilityPack to Data table

I am trying to scrape data from this site. I am able to obtain the data but now I need add the selected data to a data table. The following is very near complete but it is only returning the last record. I know its something simple but just cant figure it out. Essentially, the commented out portion for the Console.Writeline portion in the for loop will be the desired results in the datagridview after all said and done.
private void button1_Click(object sender, EventArgs e)
{
var doc = new HtmlWeb().Load("https://www.sportingcharts.com/nba/defense-vs-position/");
HtmlAgilityPack.HtmlNodeCollection teams = doc.DocumentNode.SelectNodes("//div[#class='col col-md-3']//tr/td[2]");
HtmlAgilityPack.HtmlNodeCollection points = doc.DocumentNode.SelectNodes(".//div[#class='col col-md-3']//tr/td[3]");
HtmlAgilityPack.HtmlNodeCollection positions = doc.DocumentNode.SelectNodes(".//div[#class='col col-md-3']//span[1]");
DataTable dvp_dt = new DataTable();
dvp_dt.Columns.Add("Team", typeof(string));
dvp_dt.Columns.Add("Points", typeof(string));
dvp_dt.Columns.Add("Position", typeof(string));
string[] positions_aux = positions.Where(x => x.InnerText.Length >= 6).Select(y => y.InnerText).ToArray();
DataRow row = dvp_dt.NewRow();
for (int i = 0; i < teams.Count - 1; i++)
{
var aux = i / 30;
row["Team"] = (teams[i].InnerText);
row["Points"] = (points[i].InnerText);
row["Position"] = (positions_aux[aux]);
// Console.WriteLine(teams[i].InnerText + ' ' + points[i].InnerText + ' ' + positions_aux[aux]);
}
dvp_dt.Rows.Add(row);
dataGridView2.DataSource = dvp_dt;
}
Try following :
for (int i = 0; i < teams.Count - 1; i++)
{
DataRow row = dvp_dt.NewRow();
var aux = i / 30;
row["Team"] = (teams[i].InnerText);
row["Points"] = (points[i].InnerText);
row["Position"] = (positions_aux[aux]);
}
dataGridView2.DataSource = null;
dataGridView2.DataSource = dvp_dt;

CheckBoxList In GridView Only Remember The First Option Ticked When New Row Added

I have a grid view with multiple columns which allow user to fill in the data and they are able to add a new row after finishing filling the data. Among the columns, there is a column with CheckBoxList which I allow user to multiple select the option on the CheckBoxList but every time add a new row, only the first option select by the user is remain while other selection is gone. How am I able to let the option selected by the user remain while I add a new row?
private void SetPreviousDataLecturer()
{
int rowIndex = 0;
if (ViewState["LecturerGridView"] != null)
{
DataTable dataTableCurrent = (DataTable)ViewState["LecturerGridView"];
if (dataTableCurrent.Rows.Count > 0)
{
for (int i = 0; i < dataTableCurrent.Rows.Count; i++)
{
TextBox textBoxLName = (TextBox)LecturerGridView.Rows[rowIndex].Cells[1].FindControl("LecturerName");
TextBox textBoxLID = (TextBox)LecturerGridView.Rows[rowIndex].Cells[2].FindControl("LecturerID");
TextBox textBoxLAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[3].FindControl("LecturerAddress");
TextBox textBoxLPNumber = (TextBox)LecturerGridView.Rows[rowIndex].Cells[4].FindControl("LecturerPNumber");
TextBox textBoxLEAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[5].FindControl("LecturerEAddress");
CheckBoxList checkBoxListLCourse = (CheckBoxList)LecturerGridView.Rows[rowIndex].Cells[6].FindControl("LecturerCourse");
TextBox textBoxLPassword = (TextBox)LecturerGridView.Rows[rowIndex].Cells[7].FindControl("LecturerPassword");
LecturerGridView.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
textBoxLName.Text = dataTableCurrent.Rows[i]["LecturerName"].ToString();
textBoxLID.Text = dataTableCurrent.Rows[i]["LecturerID"].ToString();
textBoxLAdd.Text = dataTableCurrent.Rows[i]["LecturerAddress"].ToString();
textBoxLPNumber.Text = dataTableCurrent.Rows[i]["LecturerPNumber"].ToString();
textBoxLEAdd.Text = dataTableCurrent.Rows[i]["LecturerEAddress"].ToString();
checkBoxListLCourse.SelectedValue = dataTableCurrent.Rows[i]["LecturerCourse"].ToString();
textBoxLPassword.Text = dataTableCurrent.Rows[i]["LecturerPassword"].ToString();
rowIndex++;
}
}
}
}
private void AddNewRowToLecturerGV()
{
int rowIndex = 0;
if (ViewState["LecturerGridView"] != null)
{
DataTable dataTableCurrent = (DataTable)ViewState["LecturerGridView"];
DataRow dataRowCurrent = null;
if (dataTableCurrent.Rows.Count > 0)
{
for (int i = 1; i <= dataTableCurrent.Rows.Count; i++)
{
TextBox textBoxLName = (TextBox)LecturerGridView.Rows[rowIndex].Cells[1].FindControl("LecturerName");
TextBox textBoxLID = (TextBox)LecturerGridView.Rows[rowIndex].Cells[2].FindControl("LecturerID");
TextBox textBoxLAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[3].FindControl("LecturerAddress");
TextBox textBoxLPNumber = (TextBox)LecturerGridView.Rows[rowIndex].Cells[4].FindControl("LecturerPNumber");
TextBox textBoxLEAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[5].FindControl("LecturerEAddress");
CheckBoxList checkBoxListLCourse = (CheckBoxList)LecturerGridView.Rows[rowIndex].Cells[6].FindControl("LecturerCourse");
TextBox textBoxLPassword = (TextBox)LecturerGridView.Rows[rowIndex].Cells[7].FindControl("LecturerPassword");
dataRowCurrent = dataTableCurrent.NewRow();
dataRowCurrent["RowNumber"] = i + 1;
dataTableCurrent.Rows[i - 1]["LecturerName"] = textBoxLName.Text;
dataTableCurrent.Rows[i - 1]["LecturerID"] = textBoxLID.Text;
dataTableCurrent.Rows[i - 1]["LecturerAddress"] = textBoxLAdd.Text;
dataTableCurrent.Rows[i - 1]["LecturerPNumber"] = textBoxLPNumber.Text;
dataTableCurrent.Rows[i - 1]["LecturerEAddress"] = textBoxLEAdd.Text;
dataTableCurrent.Rows[i - 1]["LecturerCourse"] = checkBoxListLCourse.SelectedValue.ToString();
dataTableCurrent.Rows[i - 1]["LecturerPassword"] = textBoxLPassword.Text;
rowIndex++;
}
dataTableCurrent.Rows.Add(dataRowCurrent);
ViewState["LecturerGridView"] = dataTableCurrent;
LecturerGridView.DataSource = dataTableCurrent;
LecturerGridView.DataBind();
}
}
else
{
Response.Write("ViewState is null.");
}
SetPreviousDataLecturer();
}
You need to maintain state for selected checkbox. On the button click 'Add new row' first get the state of each rows in a DataTable and add a blank row then populate that DataTable.
You need to maintain checkbox's selected item's state also. You can get selected values in a CSV as :
string selectedItems = String.Join(",",
checkBoxListLCourse.Items.OfType<ListItem>().Where(r => r.Selected)
.Select(r => r.Value));
and you can restore as :
string[] items = selectedItems.Split(',');
for (int i = 0; i < checkBoxListLCourse.Items.Count; i++)
{
if (items.Contains(checkBoxListLCourse.Items[i].Value))
{
checkBoxListLCourse.Items[i].Selected = true;
}
}
My answer. This answer has some problem like the checkbox list will automatically scroll to the most top when we tick on anything in the checkbox list.
private void SetPreviousDataLecturer()
{
int rowIndex = 0;
if (ViewState["LecturerGridView"] != null)
{
DataTable dataTableCurrent = (DataTable)ViewState["LecturerGridView"];
if (dataTableCurrent.Rows.Count > 0)
{
for (int i = 0; i < dataTableCurrent.Rows.Count; i++)
{
TextBox textBoxLName = (TextBox)LecturerGridView.Rows[rowIndex].Cells[1].FindControl("LecturerName");
TextBox textBoxLID = (TextBox)LecturerGridView.Rows[rowIndex].Cells[2].FindControl("LecturerID");
TextBox textBoxLAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[3].FindControl("LecturerAddress");
TextBox textBoxLPNumber = (TextBox)LecturerGridView.Rows[rowIndex].Cells[4].FindControl("LecturerPNumber");
TextBox textBoxLEAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[5].FindControl("LecturerEAddress");
CheckBoxList checkBoxListLCourse = (CheckBoxList)LecturerGridView.Rows[rowIndex].Cells[6].FindControl("LecturerCourse");
TextBox textBoxLPassword = (TextBox)LecturerGridView.Rows[rowIndex].Cells[7].FindControl("LecturerPassword");
LecturerGridView.Rows[i].Cells[0].Text = Convert.ToString(i + 1);
textBoxLName.Text = dataTableCurrent.Rows[i]["LecturerName"].ToString();
textBoxLID.Text = dataTableCurrent.Rows[i]["LecturerID"].ToString();
textBoxLAdd.Text = dataTableCurrent.Rows[i]["LecturerAddress"].ToString();
textBoxLPNumber.Text = dataTableCurrent.Rows[i]["LecturerPNumber"].ToString();
textBoxLEAdd.Text = dataTableCurrent.Rows[i]["LecturerEAddress"].ToString();
checkBoxListLCourse.Text = dataTableCurrent.Rows[i]["LecturerCourse"].ToString();
string lecturerCourse = dataTableCurrent.Rows[i]["LecturerCourse"].ToString();
if (!string.IsNullOrEmpty(lecturerCourse))
{
for (int j = 0; j < lecturerCourse.Split(',').Length; j++)
{
checkBoxListLCourse.Items.FindByValue(lecturerCourse.Split(',')[j].ToString()).Selected = true;
}
}
textBoxLPassword.Text = dataTableCurrent.Rows[i]["LecturerPassword"].ToString();
rowIndex++;
}
}
}
}
private void AddNewRowToLecturerGV()
{
int rowIndex = 0;
if (ViewState["LecturerGridView"] != null)
{
DataTable dataTableCurrent = (DataTable)ViewState["LecturerGridView"];
DataRow dataRowCurrent = null;
if (dataTableCurrent.Rows.Count > 0)
{
for (int i = 1; i <= dataTableCurrent.Rows.Count; i++)
{
TextBox textBoxLName = (TextBox)LecturerGridView.Rows[rowIndex].Cells[1].FindControl("LecturerName");
TextBox textBoxLID = (TextBox)LecturerGridView.Rows[rowIndex].Cells[2].FindControl("LecturerID");
TextBox textBoxLAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[3].FindControl("LecturerAddress");
TextBox textBoxLPNumber = (TextBox)LecturerGridView.Rows[rowIndex].Cells[4].FindControl("LecturerPNumber");
TextBox textBoxLEAdd = (TextBox)LecturerGridView.Rows[rowIndex].Cells[5].FindControl("LecturerEAddress");
CheckBoxList checkBoxListLCourse = (CheckBoxList)LecturerGridView.Rows[rowIndex].Cells[6].FindControl("LecturerCourse");
TextBox textBoxLPassword = (TextBox)LecturerGridView.Rows[rowIndex].Cells[7].FindControl("LecturerPassword");
dataRowCurrent = dataTableCurrent.NewRow();
dataRowCurrent["RowNumber"] = i + 1;
dataTableCurrent.Rows[i - 1]["LecturerName"] = textBoxLName.Text;
dataTableCurrent.Rows[i - 1]["LecturerID"] = textBoxLID.Text;
dataTableCurrent.Rows[i - 1]["LecturerAddress"] = textBoxLAdd.Text;
dataTableCurrent.Rows[i - 1]["LecturerPNumber"] = textBoxLPNumber.Text;
dataTableCurrent.Rows[i - 1]["LecturerEAddress"] = textBoxLEAdd.Text;
string lecturerCourse = string.Empty;
foreach (ListItem item in checkBoxListLCourse.Items)
{
if (item.Selected)
{
if (!string.IsNullOrEmpty(lecturerCourse))
{
lecturerCourse += ",";
}
lecturerCourse += item.Value;
}
}
dataTableCurrent.Rows[i - 1]["LecturerCourse"] = lecturerCourse;
dataTableCurrent.Rows[i - 1]["LecturerPassword"] = textBoxLPassword.Text;
rowIndex++;
}
dataTableCurrent.Rows.Add(dataRowCurrent);
ViewState["LecturerGridView"] = dataTableCurrent;
LecturerGridView.DataSource = dataTableCurrent;
LecturerGridView.DataBind();
}
}
else
{
Response.Write("ViewState is null.");
}
SetPreviousDataLecturer();
}

Add new row to DataGridView C#

I searching for a easy method for adding new row to datagrid. So, what I have:
dataGridView2.ColumnCount = 4;
int w = 0;
foreach (var item in tInArr)
{...
dataGridView2.Rows.Add();
dataGridView2[0, w].Value = muTat3.ToString();
dataGridView2[1, w].Value = item.ToString();
....
w++;}
Where is my mistake? I've read some articles here, but there's no answers.
if you have no datasource, then you can go the following way:
int rowIndex = dataGridView1.Rows.Add();
dataGridView1[0, rowIndex].Value = "value1"; // 0 for first column
dataGridView1[1, rowIndex].Value = "value2"; // 1 for second column
rowIndex = dataGridView1.Rows.Add();
dataGridView1[0, rowIndex].Value = "value3";
dataGridView1[1, rowIndex].Value = "value4";
in your code it should be:
// dataGridView2.ColumnCount = 4;
int w = 0;
foreach (var item in tInArr)
{...
w = dataGridView2.Rows.Add();
dataGridView2[0, w].Value = muTat3.ToString();
dataGridView2[1, w].Value = item.ToString();
....
//w++; this is not required
}
Here you can use datable then iterate your loop like this way :
foreach (DataRow rows in dt.Rows)
{..
int w = dataGridView2.Rows.Add();
dataGridView2[0, w].Value = rows[0].ToString();
dataGridView2[1, w].Value = rows[1].ToString();
}
First You create the datatable and then you can set the datasource of datagrid its long but easy to maintain.
like this
DataTable table = new DataTable();
table.Columns.Add("Check", typeof(bool));
table.Columns.Add("Path", typeof(string));
table.Columns.Add("Date", typeof(DateTime));
table.Rows.Add(false, "", DateTime.Now);
dataGridView2.DataSource = table;

Dynamic CheckBoxes in GridView Rows are not showing properly in ASP.NET

I have a gridview in which i am showing values to be checked or unchecked in gridview rows checkboxes..Now i want to these values dynamically in gridview rows but its not going to happen ..All of the checkboxes are coming checked whereas result should be different ..
here is my hardcoded code condition to show the result which is coming fine...
string[] rolesarr = Roles.GetAllRoles();
DataTable dTable = new DataTable();
dTable.Columns.Add("Select", typeof(bool));
dTable.Columns.Add("Username", typeof(string));
Array.ForEach(rolesarr, r => dTable.Columns.Add(r, typeof(bool)));
foreach (MembershipUser u in Membership.GetAllUsers())
{
DataRow dRow = dTable.NewRow();
dRow[0] = false;
dRow[1] = u.UserName;
string[] roles = Roles.GetRolesForUser(u.UserName);
dRow[2] = roles.Contains("Admin") ? true : false;
dRow[3] = roles.Contains("DPAO User") ? true : false;
dRow[4] = roles.Contains("GeneralUser") ? true : false;
dTable.Rows.Add(dRow);
}
GridView1.DataSource = dTable;
GridView1.DataBind();
Now i want to make this condition dynamic for which i have written code..
string[] rolesarr = Roles.GetAllRoles();
DataTable dTable = new DataTable();
dTable.Columns.Add("Select", typeof(bool));
dTable.Columns.Add("Username", typeof(string));
Array.ForEach(rolesarr, r => dTable.Columns.Add(r, typeof(bool)));
foreach (MembershipUser u in Membership.GetAllUsers())
{
DataRow dRow = dTable.NewRow();
dRow[0] = false;
dRow[1] = u.UserName;
string[] roles = Roles.GetRolesForUser(u.UserName);
for (int i = 0; i < roles.Length; i++)
{
string rol = roles[i];
for (int j = 2; j < dTable.Columns.Count; j++)
{
dRow[j] = roles.Contains(rol) ? true : false;
}
}
dTable.Rows.Add(dRow);
}
GridView1.DataSource = dTable;
GridView1.DataBind();
And Here is my RowDatabound event for checkboxes ..
protected void GridView1_RowDataBound1(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
CheckBox c0 = (CheckBox)e.Row.Cells[0].Controls[0];
CheckBox c2 = (CheckBox)e.Row.Cells[2].Controls[0];
CheckBox c3 = (CheckBox)e.Row.Cells[3].Controls[0];
CheckBox c4 = (CheckBox)e.Row.Cells[4].Controls[0];
c0.Enabled = c2.Enabled = c3.Enabled = c4.Enabled = true;
}
}
Please guys help me ..Thanks in advance...
the problem should be the double loops you provided.
According to your hardcoded code, you want to map between roles in the array rolesarr and roles of users, to show which roles is checked for each user.
To set values for data row at indext 2 - 4, you will have two loops, first loop to repeat rolesarr array and second loop to repeat roles array and compare them in the second loop
This is the code I mean:
string[] rolesarr = Roles.GetAllRoles();
DataTable dTable = new DataTable();
dTable.Columns.Add("Select", typeof(bool));
dTable.Columns.Add("Username", typeof(string));
Array.ForEach(rolesarr, r => dTable.Columns.Add(r, typeof(bool)));
foreach (MembershipUser u in Membership.GetAllUsers())
{
DataRow dRow = dTable.NewRow();
dRow[0] = false;
dRow[1] = u.UserName;
string[] roles = Roles.GetRolesForUser(u.UserName);
for (int i = 0; i < rolesarr.Length; i++)
{
for (int j = 0; j < roles.Length; j++)
{
if (rolesarr[i] == roles[j])
{
dRow[i + 2] = true;
break;
}
}
}
dTable.Rows.Add(dRow);
}
GridView1.DataSource = dTable;
GridView1.DataBind();
Please notice that I use data row index as i + 2 (dRow[i + 2]) in the second loop, because your role columns start at index=2, not 0, and the length must equal rolesarr.Length which you use them as role colums.

Dynamically create table in C#

I have created a table in code behind file dynamically:
The code for creating this table is like this:
protected void BindGridviewNew(Guid SubscriptionID)
{
pnlreapeter.Visible = true;
gridviewnew.Visible = true;
List<string> plannig = new List<string>();
var s = m.bussinesCollection.BussinesPlanning.GetSingleSubVersionTrueFalse(SubscriptionID);
if (s != null)
{
if (s.T1.Value)
{
plannig.Add("T1");
}
if (s.T2.Value)
{
plannig.Add("T2");
}
if (s.T3.Value)
{
plannig.Add("T3");
}
if (s.T4.Value)
{
plannig.Add("T4");
}
if (s.T5.Value)
{
plannig.Add("T5");
}
if (s.T6.Value)
{
plannig.Add("T6");
}
if (s.T7.Value)
{
plannig.Add("T7");
}
if (s.T8.Value)
{
plannig.Add("T8");
}
if (s.T9.Value)
{
plannig.Add("T9");
}
if (s.T10.Value)
{
plannig.Add("T10");
}
}
DataTable PlanningDate = m.bussinesCollection.BussinesPlanning.GetRowOfPlanningDate(SubscriptionID);
DataTable Percentage = m.bussinesCollection.BussinesPlanning.GetAllStudentsForProgressForDocentNew(SubscriptionID);
DataTable dt = new DataTable();
DataRow newrow;
newrow = dt.NewRow();
DataRow Hiddenfield;
Hiddenfield = dt.NewRow();
DataRow percentage;
percentage = dt.NewRow();
int count = plannig.Count;
for (int j = 0; j < count; j++)
{
dt.Columns.Add(plannig[j], typeof(string));
string pl = plannig[j];
string c = pl.Substring(pl.Length - 1, 1);
int x = Convert.ToInt32(c);
DataRow dr = PlanningDate.Rows[0];
DateTime date = DateTime.Parse(dr[x-1].ToString());
newrow[plannig[j]] = date.ToShortDateString();
HiddenField hf = new HiddenField();
Hiddenfield[plannig[j]] = x;
DataRow dr1 = Percentage.Rows[0];
LinkButton link = new LinkButton();
link.Text = dr1[x].ToString();
percentage[plannig[j]] = (System.Web.UI.WebControls.LinkButton) link;
}
dt.Rows.Add(newrow);
dt.Rows.Add(percentage);
// dt.Rows.Add(Hiddenfield);
gridviewnew.DataSource = dt;
gridviewnew.DataBind();
}
The problem here is,as in screen shot I am trying to get link-buttond but the column type is string so that it shows "System.Web.UI.WebControls.LinkButton"
The table I want is like:
T1 | T2 | T3
3/01/2012| 3/03/2012| 3/05/2012
100 | 50 | -
where on clicking on 100 or 50 a new popup should be displayed.
Can any one help me to create this row..?
You can not add a LinkButton to a DataTable. What you should do is bind the DataTable to the GridView, and then manually add a new row to the grid view with the link buttons, I guess in the RowDataBound event, or if there is going to be just one row with link buttons, you can add a footer to the grid view.
Check this link How to programmatically insert a row in a GridView?

Categories