Click here to Skip to main content
15,921,941 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
<table border="1">
<tr>
    <td>
             <asp:Label ID="lblMode" Text="Mode" runat="server"></asp:Label>
             <br />
            <asp:DropDownList ID="dropdownMode" runat="server">
                <asp:ListItem>Air</asp:ListItem>
                <asp:ListItem>Surface</asp:ListItem>
                <asp:ListItem>Rail</asp:ListItem>
             </asp:DropDownList>
       </td>
         <td>
         <asp:Label ID="lblVehicleNo" Text="Vehicle No." runat="server"></asp:Label>
            <asp:TextBox ID="txtVehicleNo" runat="server"></asp:TextBox>
           </td>
        <td>


XML
<asp:GridView ID="gvSelected" runat="server"
AutoGenerateColumns = "false" Font-Names = "Arial"
Font-Size = "11pt" AlternatingRowStyle-BackColor = "#C2D69B"
HeaderStyle-BackColor = "green" EmptyDataText = "No Records Selected"  >
<Columns>

<asp:TemplateField HeaderText="VehicleNo"
SortExpression="VehicleNo">
<itemtemplate>
<asp:TextBox ID="txtVehicleNo" runat="server" Width="50px"
Text='<%# Bind("VehicleNo") %>'
ReadOnly="false" ForeColor="Blue"
BorderStyle="none" BorderWidth="0px">





What I want to do is to put the textbox value into the bounded textbox i.e.I want to copy the value of textbox(txtVehicleNo) into the bounded textbox(txtVehicleNo)
Posted
Comments
Do you want to add a new row to gridview on some button click?
Member 11111143 14-Mar-15 0:22am    
No , What I want to do is above the gridview I have A textbox(txtvehicleno) I want to copy the value of that textbox in my gridview textbox(txtVehicleNo) with the help of a button. the row is already there. Iwant to put that value to every textbox of gridview

Try This.... Defiantly it will help you..

C#
DataTable dt = new DataTable();
            DataRow dr = new DataRow();
            dt.Columns.Add(new DataColumn("VehicleNo", typeof(string)));
            dr = dt.NewRow();

            dr["VehicleNo"] = txtVehicleNo.Text;
            dt.Rows.Add(dr);
            gvSelected.DataSource = dt;
            gvSelected.DataBind();



Regards
AARIF SHAIKH
 
Share this answer
 
Not clear what you want here, but you can use Eval('') function to bind the field to textbox, like this:
<asp:textbox id="txtVehicleNo" runat="server" text="<%#Eval("txtVehicleNo") %>" />
 
Share this answer
 
v2
Comments
Member 11111143 14-Mar-15 0:37am    
I just want to put one textbox value into another but the second textbox is databounded I want to do it with the help of a button is there any way
Member 11111143 14-Mar-15 0:54am    
Text='<%# Bind("VehicleNo") %>',I am already using this then how will this work
Modi Mayank 14-Mar-15 1:55am    
still didn't get your question.
Member 11111143 14-Mar-15 2:01am    
I simply want to copy one textbox value into a databounded textbox with the help of a button i.e.
from: <asp:TextBox ID="txtVehicleNo" runat="server">
to: <asp:TemplateField HeaderText="VehicleNo"
SortExpression="VehicleNo">
<itemtemplate>
<asp:TextBox ID="txtVehicleNo" runat="server" Width="50px"
Text='<%# Bind("VehicleNo") %>'
ReadOnly="true" ForeColor="Blue"
BorderStyle="none" BorderWidth="0px">


Modi Mayank 14-Mar-15 2:22am    
Then simply call javascript function on button click event (like onclick="myfunction();") and add class in your bounded field "VehicleNo" (like cssclass="tUpdate") which will find all the gridview bounded textboxes that you want to update on button click. In function you can get your textbox txtVehicleNo value (like var vNo = $("txtVehicleNo").val();) and now update the bounded textboxes with the value (like $(".tUpdate").val(vNo);) just retrieved by jQuery.

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