I have a two buttons edit and submit in my gridview.What i want is to place a textbox on second column quantity when i clicked edit so that i can change the value in the textbox.However it is not working out.Below is my html and C# code for the same.Any help would be appreciated.
<asp:Panel ID="pnlOrderLineInfo"
style="Z-INDEX: 101; LEFT: 29px; POSITION: absolute; TOP: 243px"
runat="server" Height="102px" Width="327px">
<asp:Image ID="Image5" runat="server" Height="30px"
ImageUrl="~/Images/scanitem.png" />
| <asp:TextBox id="txtOrderLineNo" Runat="server"
ontextchanged="txtOrderLineNo_TextChanged" > |
<asp:ImageButton ID="pnlbtnsubmit" runat="server" Height="30px"
ImageUrl="~/Images/submit.png" onclick="pnlbtnsubmit_Click" />
<asp:ImageButton ID="pnlbtncancel" runat="server" Height="30px"
ImageUrl="~/Images/cancel.png" onclick="pnlbtncancel_Click" />
<asp:Label ID="lblmsgordlines" runat="server" Text="">
|
<asp:GridView ID="gvorderdetail" runat="server"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None"
onrowcommand="gvorderdetail_RowCommand"
onrowdatabound="gvorderdetail_RowDataBound">
<alternatingrowstyle backcolor="White" forecolor="#284775">
<columns>
<asp:TemplateField HeaderText="ItemCode">
<itemtemplate>
<asp:Label ID="lblitemcode" runat="server" Text='<%# Eval("ItemCode")%>'>
<asp:TemplateField HeaderText="Quantity">
<itemtemplate>
<asp:Label ID="lblitemqty" runat="server" Text='<%# Eval("ItemQty")%>'>
<edititemtemplate>
<asp:TextBox ID="txtitemqty" runat="server" Text='<%# Bind("ItemQty") %>'>
<asp:TemplateField HeaderText="LineVal">
<itemtemplate>
<asp:Label ID="lblitemval" runat="server" Text='<%# Eval("LineVal")%>'>
<asp:TemplateField HeaderText="Date">
<itemtemplate>
<asp:Label ID="lblitemdate" runat="server" Text='<%# Eval("UpdDate","{0:u}")%>'>
<asp:TemplateField>
<itemtemplate>
<asp:Button ID="btnchange" runat="server" Text="Edit" OnClick="btnchange_Click" CommandName="change" />
<asp:TemplateField>
<itemtemplate>
<asp:Button ID="btnupdate" runat="server" Text="Submit" OnClick="btnupdate_Click" CommandName="update" />
<editrowstyle backcolor="#999999">
<footerstyle backcolor="#5D7B9D" font-bold="True" forecolor="White">
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<pagerstyle backcolor="#284775" forecolor="White" horizontalalign="Center">
<rowstyle backcolor="#F7F6F3" forecolor="#333333">
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<sortedascendingcellstyle backcolor="#E9E7E2">
<sortedascendingheaderstyle backcolor="#506C8C">
<sorteddescendingcellstyle backcolor="#FFFDF8">
<sorteddescendingheaderstyle backcolor="#6F8DAE">
This is the C# code:
protected void gvorderdetail_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "change")
{
TextBox tbx = (TextBox)gvorderdetail.Rows[0].FindControl("txtitemqty");
}
}
protected void btnchange_Click(object sender, EventArgs e)
{
Button btn = (Button)sender;
GridViewRow gvr = (GridViewRow)btn.NamingContainer;
int getindex = gvr.RowIndex;
gvorderdetail.Rows[getindex].Cells[3].Style.Value = "red";
gvorderdetail.Rows[getindex].Cells[0].Attributes["style"] = "background-color:Red";
gvorderdetail.Rows[getindex].Cells[1].Attributes["style"] = "background-color:Red";
gvorderdetail.Rows[getindex].Cells[2].Attributes["style"] = "background-color:Red";
TextBox tbx = (TextBox)gvorderdetail.Rows[0].FindControl("txtitemqty");
}
But the code above doesnt place the textbox in the quantity column.