Only for the second column you may use a TemplateField with a label in ItemTemPlate and a TextBox in EditIemTemplate binding their Text Values to required data field. Then in edit mode user will be able to edit the text in second column.
Kindly mark this post as "Answer", if it helped you.
just for reference, its sitting inside a collapsible panel
<p>
<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
<asp:Button ID="ModalButton" runat="server" CssClass="style2"
Text="Click here to Add Allocation Percentage" Width="257px" />
</p>
<p>
<asp:Panel ID="pHeader" runat="server" CssClass="cpHeader">
<asp:Label ID="lblText" runat="server" />
</asp:Panel>
<asp:Panel ID="pBody" runat="server" CssClass="cpBody" >
<asp:GridView ID="UserAllocationGrid" runat="server">
</asp:GridView>
This is my new area!!! Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur
</asp:Panel>
<asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server"
TargetControlID="pBody" CollapseControlID="pHeader" ExpandControlID="pHeader"
Collapsed="true" TextLabelID="lblText" CollapsedText="Click to Show Content.."
ExpandedText="Click to Hide Content.."
CollapsedSize="0">
</asp:CollapsiblePanelExtender>
okay so this worked. I added a few things. So now, if there are 5 managers(5rows), then it takes 100 / 5 = 20. And populated 20 in all textboxes in column 2. So now my goal is to have a footer sum the 2nd column. Which would equal 100 in this case.
I didn't get your intention completely. One column shows managers. What is in second column?. If equally shared for all managers why should user edit it? if it shows percentage the sum will always be 100. Then why it should be shown. It will be a static
Text 100 always. Please explain your idea clearly so that I can give you some guidance if it fits within my head.
Kindly mark this post as "Answer", if it helped you.
I apologize for not being clear. The purpose is as follow... when page loads up(or button is pressed), I want the second column to be equally shared. So yes, initially it will equal 100. But then I want the user, to specify new amounts in the second
column. The summation in the footer is to be updated each time user inputs a new amount. Eventually I will use the user entries for something completely different. The summation is to let user know the total of what they are entering.
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();basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 02:31 AM|LINK
Only for the second column you may use a TemplateField with a label in ItemTemPlate and a TextBox in EditIemTemplate binding their Text Values to required data field. Then in edit mode user will be able to edit the text in second column.
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 03:11 AM|LINK
could you be a bit more specific with some code please? this is above my head a bit. How can I use a template field on this?
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 03:47 AM|LINK
Sure, I can show you some sample code.. Please show me your GridView markup
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 09:57 AM|LINK
<asp:GridView ID="UserAllocationGrid" runat="server"></asp:GridView>
just for reference, its sitting inside a collapsible panel
<p> <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:Button ID="ModalButton" runat="server" CssClass="style2" Text="Click here to Add Allocation Percentage" Width="257px" /> </p> <p> <asp:Panel ID="pHeader" runat="server" CssClass="cpHeader"> <asp:Label ID="lblText" runat="server" /> </asp:Panel> <asp:Panel ID="pBody" runat="server" CssClass="cpBody" > <asp:GridView ID="UserAllocationGrid" runat="server"> </asp:GridView> This is my new area!!! Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur </asp:Panel> <asp:CollapsiblePanelExtender ID="CollapsiblePanelExtender1" runat="server" TargetControlID="pBody" CollapseControlID="pHeader" ExpandControlID="pHeader" Collapsed="true" TextLabelID="lblText" CollapsedText="Click to Show Content.." ExpandedText="Click to Hide Content.." CollapsedSize="0"> </asp:CollapsiblePanelExtender>basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 02:41 PM|LINK
Try this sample. But I am notsure why do you want to make the cell editable.
ListBox and GridView
<asp:ListBox ID="ListBox1" runat="server"> <asp:ListItem>Manager1</asp:ListItem> <asp:ListItem>Manager2</asp:ListItem> <asp:ListItem>Manager3</asp:ListItem> <asp:ListItem>Manager4</asp:ListItem> </asp:ListBox> <asp:GridView ID="UserAllocationGrid" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundField DataField="Manager" HeaderText="Manager" SortExpression="managers" /> <asp:TemplateField HeaderText="Allocation Percentage"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text= '<%# Bind("AllocationPercentage") %>' BorderStyle="None"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView>Code Behind
void fillGV() { DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("AllocationPercentage"); // go through listbox1 to find selected managers = selectedManagersList List<string> selectedManagersListDates = new List<string>(); int counterR = 0; foreach (ListItem strItem in ListBox1.Items) { //selectedManagersListDates.Add(strItem.Value); DataRow drManagerName = UserAllocationTable.NewRow(); UserAllocationTable.Rows.Add(drManagerName); UserAllocationTable.Rows[counterR]["Manager"] = strItem.Value; counterR = counterR + 1; } // ViewState["UserAllocationTable"] = UserAllocationTable; UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind(); }Use this void in any event I did it in abutton click
protected void Button1_Click(object sender, EventArgs e) { fillGV(); }Please note the changes I made to your code
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 02:52 PM|LINK
I will originally post integer values in the 2nd column... but the user needs to be able to change the values.
thanks, I will try your code and come back to you
appreciate the help
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 05:28 PM|LINK
okay so this worked. I added a few things. So now, if there are 5 managers(5rows), then it takes 100 / 5 = 20. And populated 20 in all textboxes in column 2. So now my goal is to have a footer sum the 2nd column. Which would equal 100 in this case.
I found someone attempting a similar type concept here... http://forums.asp.net/p/1381638/2927230.aspx
Would you mind helping me converted this users code into code I would need? Or should I make a new thread?
I'm guessing I have to somehow use the onkeyup="javascript.add(); *code found on that link*
But i'm not sure how to incorporate it.
The goal of this is, when a user changes one of the textboxes, I want the footer to automatically recalculate the summation.
javascript code:
<script language
="javascript">
function Add()
{
//alert('Called');var rows=document.getElementsByTagName('TR');
total=0;
for(i=1;i<rows.length-1;i++)
{
if(rows[i].children[1].children[0].value.trim()!="")
{
total+=parseInt(rows[i].children[1].children[0].value);
}
}
rows[rows.length-1].children[1].children[0].value=total;
total=0;
}
my code below
<asp:GridView ID="UserAllocationGrid" runat="server" AutoGenerateColumns="false" ShowFooter="true" FooterStyle-CssClass="FooterStyle"> <Columns> <asp:BoundField DataField="Manager" HeaderText="Manager" SortExpression="Managers" /> <asp:TemplateField HeaderText="Allocation Percentage"> <ItemTemplate> <asp:TextBox ID="TextBox1" runat="server" Text = '<%# Bind("AllocationPercentage") %>' BorderStyle="None"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> DataTable UserAllocationTable = new DataTable(); UserAllocationTable.Columns.Add("Manager"); UserAllocationTable.Columns.Add("AllocationPercentage"); // 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; } } double equalPercentage = 100 / (Convert.ToDouble(counterR)); equalPercentage = Math.Round(equalPercentage, 2); for (int a = 0; a < counterR; a++) { UserAllocationTable.Rows[a][1] = equalPercentage; } //UserAllocationTable.Rows[0][1] = "tester"; UserAllocationGrid.DataSource = UserAllocationTable; UserAllocationGrid.DataBind();basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 06:47 PM|LINK
I didn't get your intention completely. One column shows managers. What is in second column?. If equally shared for all managers why should user edit it? if it shows percentage the sum will always be 100. Then why it should be shown. It will be a static Text 100 always. Please explain your idea clearly so that I can give you some guidance if it fits within my head.
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 01, 2012 06:56 PM|LINK
I apologize for not being clear. The purpose is as follow... when page loads up(or button is pressed), I want the second column to be equally shared. So yes, initially it will equal 100. But then I want the user, to specify new amounts in the second column. The summation in the footer is to be updated each time user inputs a new amount. Eventually I will use the user entries for something completely different. The summation is to let user know the total of what they are entering.