Click here to Skip to main content
15,881,852 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have 4 textboxes and one submit button.when i enter data in textboxes and press Submit button the data will be stored in DB and shows in Gridview with Edit and Delete options.when i press the Edit button in Grid View perticular row values will be append to textboxes.
i tried with Onrowcommand but it gives error.pls give me your valuble suggistions.
OnRow command coding

protected void onrowchanged_gv(object sender, EventArgs e)
{
GridViewRow row = g1.SelectedRow;
txtdate.Text = row.Cells[4].Text;
txtinvnum.Text = row.Cells[0].Text;
txtinvdet.Text = Convert.ToString((TextBox)row.Cells[1].Controls[0]);
txtcmpname.Text = Convert.ToString((TextBox)row.Cells[2].Controls[0]);
txtaccname.Text = Convert.ToString((TextBox)row.Cells[3].Controls[0]);
txtinvamt.Text = Convert.ToString((TextBox)row.Cells[5].Controls[0]);

}
My grid view in aspx
XML
<asp:GridView ID="g1" runat="server" AutoGenerateColumns="false" OnSelectedIndexChanged="onrowchanged_gv" >
   <Columns>
   <asp:BoundField DataField="invoice_num" HeaderText="Invoice Number" />
   <asp:BoundField DataField="invoice_details" HeaderText="Invoice Details" />
   <asp:BoundField DataField="company_name" HeaderText="Company Name" />
   <asp:BoundField DataField="account_name" HeaderText="Account Name" />
   <asp:BoundField DataField="invoice_date" HeaderText="Date" />
   <asp:BoundField DataField="invoice_amount" HeaderText="Amount" />
    <asp:TemplateField >
   <ItemTemplate>
   <asp:LinkButton ID="lkbtn1" runat="server" Text="Edit" CommandName="EDIT"></asp:LinkButton>
   </ItemTemplate>
   </asp:TemplateField>
   </Columns>
   </asp:GridView>
Posted

 
Share this answer
 
Comments
benzimen 19-Dec-14 0:20am    
Thanks for u reply.but it is not my requirement.when i press the Edit button in Gridview that values will be added to out side of Gridview. values should be append to Textboxes.
convert your bound fields to template field as labels, and use a button instead of linkbutton.
then on g1_rowcommand event

If e.CommandName = "EDIT" Then
Dim btn As Button = DirectCast(e.CommandSource, Button)
Dim gvr As GridViewRow = DirectCast(btn.NamingContainer, GridViewRow)
'get value from invoice_num
Dim InvoiceNumLabel as Label = Directcast(gvr.FindControl("InvoiceNumlabel"), Label)
'write value to TextBox
InvoiceNLabelTextBox.text = InvoiceNumlabel.text.toString()
else
end if


I hope this helps
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900