Hi - My Gridview control is inside a update panel and has the textbox in which I' m trying to get the text changed event. here is some code I have been using. All I want is to capture the old and new values in the margin column in the grid view. Can you
please suggest how I could get this to work?
Thanks
protected void btnUpdateVolMar_Click(object sender, EventArgs e)
{
string margin = "0";
float updateMargin = float.Parse("0");
bool applyMargin = false;
foreach (GridViewRow gvr in gvVolMar.Rows)
{
TextBox txtCatMargin = (TextBox)gvr.Cells[3].FindControl("txtCatMargin");
TextBox txtCatVol = (TextBox)gvr.Cells[4].FindControl("txtCatVol");
//only update the corresponding ones otherwise this would generate a cartesian product : Mythili apr7 2010
if (txtCatMargin != null)
{
// Update the valid volume margin row
if (txtCatVol != null && txtCatVol.Visible)
{
// Main category, check for override
DataRow drow = DAVolMar.GetVolMarByID(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString()));
if (float.Parse(drow["Margin"].ToString()) != float.Parse(txtCatMargin.Text))
{
applyMargin = true;
updateMargin = float.Parse(txtCatMargin.Text);
}
else
applyMargin = false;
DataTable dt = DAVolMar.GetCategoriesByMarketPlan(mpID);
foreach (DataRow row in dt.Rows)
{
if ((gvr.Cells[1].Text.ToString() == row["CatName"].ToString())
margin = row["Margin"].ToString();
DAVolMar.UpdateMarketPlanVolMar(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString()), float.Parse(txtCatMargin.Text), float.Parse(txtCatVol.Text),"100");
}
else
{
if (applyMargin)
txtCatMargin.Text = updateMargin.ToString("0.00");
//DAVolMar.UpdateMarketPlanVolMar(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString()), float.Parse(txtCatMargin.Text));
}
}
}
}
Amulu
Member
118 Points
251 Posts
TextBox text changed event with in a Gridview.
Apr 13, 2010 05:59 PM|LINK
Hi - My Gridview control is inside a update panel and has the textbox in which I' m trying to get the text changed event. here is some code I have been using. All I want is to capture the old and new values in the margin column in the grid view. Can you please suggest how I could get this to work?
Thanks
protected void btnUpdateVolMar_Click(object sender, EventArgs e) { string margin = "0"; float updateMargin = float.Parse("0"); bool applyMargin = false; foreach (GridViewRow gvr in gvVolMar.Rows) { TextBox txtCatMargin = (TextBox)gvr.Cells[3].FindControl("txtCatMargin"); TextBox txtCatVol = (TextBox)gvr.Cells[4].FindControl("txtCatVol"); //only update the corresponding ones otherwise this would generate a cartesian product : Mythili apr7 2010 if (txtCatMargin != null) { // Update the valid volume margin row if (txtCatVol != null && txtCatVol.Visible) { // Main category, check for override DataRow drow = DAVolMar.GetVolMarByID(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString())); if (float.Parse(drow["Margin"].ToString()) != float.Parse(txtCatMargin.Text)) { applyMargin = true; updateMargin = float.Parse(txtCatMargin.Text); } else applyMargin = false; DataTable dt = DAVolMar.GetCategoriesByMarketPlan(mpID); foreach (DataRow row in dt.Rows) { if ((gvr.Cells[1].Text.ToString() == row["CatName"].ToString()) margin = row["Margin"].ToString(); DAVolMar.UpdateMarketPlanVolMar(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString()), float.Parse(txtCatMargin.Text), float.Parse(txtCatVol.Text),"100"); } else { if (applyMargin) txtCatMargin.Text = updateMargin.ToString("0.00"); //DAVolMar.UpdateMarketPlanVolMar(int.Parse(gvVolMar.DataKeys[gvr.RowIndex].Value.ToString()), float.Parse(txtCatMargin.Text)); } } } }<asp:UpdatePanel ID="UpdatePanel5" runat="server"> <ContentTemplate> <br /> <asp:GridView ID="gvVolMar" runat="server" AutoGenerateColumns="False" BorderColor="Black" BorderStyle="Solid" BorderWidth="1px" CssClass="dataview" Width="90%" EmptyDataText="0 Records returned" DataKeyNames="MarketPlanVolMarID" OnRowDataBound="gvVolMar_RowDataBound" DataSourceID="dsVolMar" EnableViewState="False" > <Columns> <asp:HyperLinkField /> <asp:BoundField DataField="CatName" HeaderText="Category" ReadOnly="True"> <ControlStyle Width="50px" /> <ItemStyle Wrap="False" /> </asp:BoundField> <asp:BoundField DataField="ClassName" HeaderText="Class" ReadOnly="True"> <ControlStyle Width="50px" /> <ItemStyle Wrap="False" /> </asp:BoundField> <asp:BoundField DataField="NumPlanned" HeaderText="# Planned"> <ItemStyle Width="50px" /> </asp:BoundField> <asp:TemplateField HeaderText="Target Margin"> <ItemTemplate> <asp:TextBox ID="txtCatMargin" runat="server" Text='<%# Bind("Margin", "{0:0.0}") %>' Width="40px">%</asp:TextBox>% </ItemTemplate> <ItemStyle Width="75px" /> </asp:TemplateField> <asp:TemplateField HeaderText="Target Volume"> <ItemTemplate> $<asp:TextBox ID="txtCatVol" runat="server" Text='<%# Bind("Volume", "{0:0}") %>' Width="100px"></asp:TextBox> <cc1:MaskedEditExtender ID="MaskedEditExtender1" runat="server" TargetControlID="txtCatVol" Mask="99,999,999" MessageValidatorTip="true" OnFocusCssClass="MaskedEditFocus" OnInvalidCssClass="MaskedEditError" MaskType="Number" InputDirection="RightToLeft" AcceptNegative="Left" DisplayMoney="Left"> </cc1:MaskedEditExtender> </ItemTemplate> <ItemStyle Width="150px" /> </asp:TemplateField> </Columns> </asp:GridView> <br /> <asp:Button ID="btnUpdateVolMar" runat="server" Text="Update" OnClick="btnUpdateVolMar_Click" /> </ContentTemplate> </asp:UpdatePanel>MetalAsp.Net
All-Star
112157 Points
18249 Posts
Moderator
Re: TextBox text changed event with in a Gridview.
Apr 13, 2010 06:11 PM|LINK
Don't really know for sure, but maybe change these:
TextBox txtCatMargin = (TextBox)gvr.FindControl("txtCatMargin"); TextBox txtCatVol = (TextBox)gvr.FindControl("txtCatVol");Also add a check to make sure you're dealing with datarows, like so:
if (gvr.RowType == DataControlRowType.DataRow) { // Do all the processing here }Amulu
Member
118 Points
251 Posts
Re: TextBox text changed event with in a Gridview.
Apr 13, 2010 06:28 PM|LINK
I was trying suggestion in this link also but it doesnt work for me
http://forums.asp.net/p/1539720/3748614.aspx
Please help
Thanks
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: TextBox text changed event with in a Gridview.
Apr 16, 2010 01:18 AM|LINK
If you want to get the old and new values, you can just use this instead:
protected void GridView_RowUpdating(object sender, GridViewRowUpdateEventArgs e)
{
e.NewValues["Column"]/e.OleValues["Column"]
}
Amulu
Member
118 Points
251 Posts
Re: TextBox text changed event with in a Gridview.
Apr 19, 2010 08:20 PM|LINK
resolved this issue by writing an update and insert trigger which was much easier than this.
Thanks