I will be temporarily saving these values, maybe to "SESSION", possibly in an array. But only while I do my calculations on a different page, then I can discard them.
void ShowTotal(object sender, EventArgs e)
{
int percent = 0;
int totalp = 0;
foreach (GridViewRow gvr in UserAllocationGrid.Rows)
if (gvr.RowType == DataControlRowType.DataRow)
{
TextBox TB = (TextBox)(gvr.FindControl("TextBox1"));
percent = Convert.ToInt32(TB.Text);
totalp = totalp + percent;
}
GridViewRow r = UserAllocationGrid.FooterRow;
Label lbl = (Label)(r.FindControl("Label2"));
lbl.Text = totalp.ToString();
}
Thi is for putting equally shared percentage in each row based on number of managers.
thank you so much for all your work. If I copy your exact code I get .
TextBox1_TextChanged does not exist? What is this supposed to point to?
Error 4 'ASP.userform_aspx' does not contain a definition for 'TextBox1_TextChanged' and no extension method 'TextBox1_TextChanged' accepting a first argument of type 'ASP.userform_aspx' could be found (are you missing a using directive or an assembly reference?) C:\SFProject\WebSite6\Userform.aspx 133
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 05:46 AM|LINK
OK, I will come back with some sample code for you. Before that let me know don't you need to save somewhere all the changes made by an user?
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 11:36 AM|LINK
I will be temporarily saving these values, maybe to "SESSION", possibly in an array. But only while I do my calculations on a different page, then I can discard them.
thanks!!!
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 12:24 PM|LINK
This can be used for showing total in footer
void ShowTotal(object sender, EventArgs e) { int percent = 0; int totalp = 0; foreach (GridViewRow gvr in UserAllocationGrid.Rows) if (gvr.RowType == DataControlRowType.DataRow) { TextBox TB = (TextBox)(gvr.FindControl("TextBox1")); percent = Convert.ToInt32(TB.Text); totalp = totalp + percent; } GridViewRow r = UserAllocationGrid.FooterRow; Label lbl = (Label)(r.FindControl("Label2")); lbl.Text = totalp.ToString(); } Thi is for putting equally shared percentage in each row based on number of managers.protected void UserAllocationGrid_DataBound(object sender, EventArgs e) { int percent = 100 / UserAllocationGrid.Rows.Count; Response.Write(percent.ToString()); foreach(GridViewRow gvr in UserAllocationGrid.Rows) if (gvr.RowType == DataControlRowType.DataRow) { TextBox TB = (TextBox)(gvr.FindControl("TextBox1")); TB.Text = percent.ToString(); } }<asp:GridView ID="UserAllocationGrid" runat="server" AutoGenerateColumns="False" ShowFooter="True" ondatabound="UserAllocationGrid_DataBound" > <Columns> <asp:TemplateField HeaderText="Manager"> <ItemTemplate> <asp:Label ID="Label1" runat="server" Text= '<%# Bind("manager") %>'></asp:Label> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="Allocation" > <ItemTemplate > <asp:TextBox ID="TextBox1" runat="server" Text= '<%# Bind("AllocationPercentage") %>' BorderStyle="None" ontextchanged="TextBox1_TextChanged" style="height: 18px" ></asp:TextBox> </ItemTemplate> <FooterTemplate> <asp:Label ID="Label2" runat="server" ></asp:Label> </FooterTemplate> </asp:TemplateField> </Columns> </asp:GridView>(Talk less..Work more)
Giri_DOTNET
Participant
1239 Points
242 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 01:09 PM|LINK
hi,
see this link
http://www.codeproject.com/Articles/18136/Edit-Individual-GridView-Cells-in-ASP-NET
gridview
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 03:46 PM|LINK
thank you so much for all your work. If I copy your exact code I get .
TextBox1_TextChanged does not exist? What is this supposed to point to?
Error 4 'ASP.userform_aspx' does not contain a definition for 'TextBox1_TextChanged' and no extension method 'TextBox1_TextChanged' accepting a first argument of type 'ASP.userform_aspx' could be found (are you missing a using directive or an assembly reference?) C:\SFProject\WebSite6\Userform.aspx 133
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 04:03 PM|LINK
Delete this from html
ontextchanged="TextBox1_TextChangede
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 04:07 PM|LINK
and where/how do you launch ShowTotal()?
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 05:12 PM|LINK
In any event you need.
(Talk less..Work more)
solarissf
0 Points
60 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 05:26 PM|LINK
say I want it on a button for now, how do I link it to the button?
basheerkal
Star
10672 Points
2426 Posts
Re: Make 1 column in gridview editable for user
May 02, 2012 05:30 PM|LINK
In click event of the Button call ShowTotal()
protected void Button1_Click(object sender, EventArgs e) { ShowTotal(); }(Talk less..Work more)