Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
0 Points
60 Posts
May 01, 2012 01:22 AM|LINK
Hi All,
Hopefully someone can help me answer this. I populated a gridview using the first way below.
Now I just want to make that second column editable for the user to type in info. Can't seem to figure it out.
Then I tried making the grid a second way, but that just puts headers without my rows of data.
Can anyone see what I'm doing wrong?
Thanks!!!
//FIRST WAY DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("Allocation Percentage"); // go through listbox1 to find selected managers = selectedManagersList List<string> selectedManagersListDates = new List<string>(); int counterR = 0; foreach (ListItem strItem in ListBox1.Items) { if (strItem.Selected) { //selectedManagersListDates.Add(strItem.Value); DataRow drManagerName = UserAllocationTable.NewRow(); UserAllocationTable.Rows.Add(drManagerName); UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value; counterR = counterR + 1; } } UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind(); //SECOND WAY DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("Allocation Percentage"); // go through listbox1 to find selected managers = selectedManagersList List<string> selectedManagersListDates = new List<string>(); int counterR = 0; foreach (ListItem strItem in ListBox1.Items) { if (strItem.Selected) { //selectedManagersListDates.Add(strItem.Value); DataRow drManagerName = UserAllocationTable.NewRow(); UserAllocationTable.Rows.Add(drManagerName); UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value; counterR = counterR + 1; } } UserAllocationGrid.AutoGenerateColumns = false; BoundField bf1 = new BoundField(); bf1.HeaderText = "Manager"; bf1.ReadOnly = true; BoundField bf2 = new BoundField(); bf2.HeaderText = "Allocation Percentage"; bf2.ReadOnly = false; UserAllocationGrid.Columns.Add(bf1); UserAllocationGrid.Columns.Add(bf2); UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind();
solarissf
0 Points
60 Posts
Make 1 column in gridview editable for user
May 01, 2012 01:22 AM|LINK
Hi All,
Hopefully someone can help me answer this. I populated a gridview using the first way below.
Now I just want to make that second column editable for the user to type in info. Can't seem to figure it out.
Then I tried making the grid a second way, but that just puts headers without my rows of data.
Can anyone see what I'm doing wrong?
Thanks!!!
//FIRST WAY DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("Allocation Percentage"); // go through listbox1 to find selected managers = selectedManagersList List<string> selectedManagersListDates = new List<string>(); int counterR = 0; foreach (ListItem strItem in ListBox1.Items) { if (strItem.Selected) { //selectedManagersListDates.Add(strItem.Value); DataRow drManagerName = UserAllocationTable.NewRow(); UserAllocationTable.Rows.Add(drManagerName); UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value; counterR = counterR + 1; } } UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind(); //SECOND WAY DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("Allocation Percentage"); // go through listbox1 to find selected managers = selectedManagersList List<string> selectedManagersListDates = new List<string>(); int counterR = 0; foreach (ListItem strItem in ListBox1.Items) { if (strItem.Selected) { //selectedManagersListDates.Add(strItem.Value); DataRow drManagerName = UserAllocationTable.NewRow(); UserAllocationTable.Rows.Add(drManagerName); UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value; counterR = counterR + 1; } } UserAllocationGrid.AutoGenerateColumns = false; BoundField bf1 = new BoundField(); bf1.HeaderText = "Manager"; bf1.ReadOnly = true; BoundField bf2 = new BoundField(); bf2.HeaderText = "Allocation Percentage"; bf2.ReadOnly = false; UserAllocationGrid.Columns.Add(bf1); UserAllocationGrid.Columns.Add(bf2); UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind();