how to pass the ID of a text box in a gridview to a javascript
-
i am developing a web based application where i use i want to pass textbox ID which is in a grid view to the java script. how it can be possible Sourav ghosh
-
i am developing a web based application where i use i want to pass textbox ID which is in a grid view to the java script. how it can be possible Sourav ghosh
Don't repost. Check Ignore HTML tags check box to post HTML code
please don't forget to vote on the post that helped you.
-
i am developing a web based application where i use i want to pass textbox ID which is in a grid view to the java script. how it can be possible Sourav ghosh
-
i am developing a web based application where i use i want to pass textbox ID which is in a grid view to the java script. how it can be possible Sourav ghosh
-
<asp:GridView id="GridView1" runat="server" Font-Size="X-Small" ForeColor="#333333" Width="802px" AllowPaging="True" GridLines="None" CellPadding="4" ShowFooter="false" AutoGenerateColumns="False" CssClass="grid-view" OnDataBound="GridView1_DataBound">
<EmptyDataTemplate>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="No Data Found"></asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="ORDER_NO" HeaderText="ORD_NO" ></asp:BoundField>
<asp:BoundField DataField="ITEM_NO" HeaderText="ITEM_NO" ></asp:BoundField>
<asp:BoundField DataField="BALTONS" HeaderText="BALTONS" ></asp:BoundField>
<asp:BoundField DataField="ORDDATE" HeaderText="ORDDATE" ></asp:BoundField>
<asp:BoundField DataField="DUEDATE" HeaderText="DUEDATE" ></asp:BoundField>
<asp:BoundField DataField="MATNR" HeaderText="MAT_NO" ></asp:BoundField>
<asp:BoundField DataField="DESCRIPTION" HeaderText="MAT_DESCP"><HeaderStyle Width="5000px" /><ItemStyle Width="5000px" /></asp:BoundField>
<asp:TemplateField HeaderText="PLANQTY">
<ItemTemplate><asp:TextBox ID="txtplanqty" runat="server" BackColor="#ffffcc" OnTextChanged="txtplanqty\_TextChanged" AutoPostBack="true" Font-Size="x-Small" Text='<%# Eval("PLAN\_QTY") %>' Width="70px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="TRGT\_PRD"> <ItemTemplate> <asp:TextBox ID="txttrgtprd" runat="server" Font-Size="X-Small" onfocus="getdata(this)" OnTextChanged="txttrgtprd\_TextChanged" BackColor="#ffffcc" Width="70px" Text='<%# Eval("TRGT\_PRD") %>' AutoPostBack="true"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#EFF3FB" /> <EditRowStyle BackColor="#2461BF" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
-
Please give more info about what you are trying to achieve, as often you dont even need the ID of the textbox. If you do, a textbox has a UniqueID property which you can use from Javascript
<pre>
<asp:GridView id="GridView1" runat="server" Font-Size="X-Small" ForeColor="#333333" Width="802px" AllowPaging="True" GridLines="None" CellPadding="4" ShowFooter="false" AutoGenerateColumns="False" CssClass="grid-view" OnDataBound="GridView1_DataBound">
<EmptyDataTemplate>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="No Data Found"></asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="ORDER_NO" HeaderText="ORD_NO" ></asp:BoundField>
<asp:BoundField DataField="ITEM_NO" HeaderText="ITEM_NO" ></asp:BoundField>
<asp:BoundField DataField="BALTONS" HeaderText="BALTONS" ></asp:BoundField>
<asp:BoundField DataField="ORDDATE" HeaderText="ORDDATE" ></asp:BoundField>
<asp:BoundField DataField="DUEDATE" HeaderText="DUEDATE" ></asp:BoundField>
<asp:BoundField DataField="MATNR" HeaderText="MAT_NO" ></asp:BoundField>
<asp:BoundField DataField="DESCRIPTION" HeaderText="MAT_DESCP"><HeaderStyle Width="5000px" /><ItemStyle Width="5000px" /></asp:BoundField>
<asp:TemplateField HeaderText="PLANQTY">
<ItemTemplate><asp:TextBox ID="txtplanqty" runat="server" BackColor="#ffffcc" OnTextChanged="txtplanqty\_TextChanged" AutoPostBack="true" Font-Size="x-Small" Text='<%# Eval("PLAN\_QTY") %>' Width="70px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="TRGT\_PRD"> <ItemTemplate> <asp:TextBox ID="txttrgtprd" runat="server" Font-Size="X-Small" onfocus="getdata(this)" OnTextChanged="txttrgtprd\_TextChanged" BackColor="#ffffcc" Width="70px" Text='<%# Eval("TRGT\_PRD") %>' AutoPostBack="true"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White
-
<asp:GridView id="GridView1" runat="server" Font-Size="X-Small" ForeColor="#333333" Width="802px" AllowPaging="True" GridLines="None" CellPadding="4" ShowFooter="false" AutoGenerateColumns="False" CssClass="grid-view" OnDataBound="GridView1_DataBound">
<EmptyDataTemplate>
<asp:Label ID="Label1" runat="server" Font-Bold="True" ForeColor="Red" Text="No Data Found"></asp:Label>
</EmptyDataTemplate>
<Columns>
<asp:BoundField DataField="ORDER_NO" HeaderText="ORD_NO" ></asp:BoundField>
<asp:BoundField DataField="ITEM_NO" HeaderText="ITEM_NO" ></asp:BoundField>
<asp:BoundField DataField="BALTONS" HeaderText="BALTONS" ></asp:BoundField>
<asp:BoundField DataField="ORDDATE" HeaderText="ORDDATE" ></asp:BoundField>
<asp:BoundField DataField="DUEDATE" HeaderText="DUEDATE" ></asp:BoundField>
<asp:BoundField DataField="MATNR" HeaderText="MAT_NO" ></asp:BoundField>
<asp:BoundField DataField="DESCRIPTION" HeaderText="MAT_DESCP"><HeaderStyle Width="5000px" /><ItemStyle Width="5000px" /></asp:BoundField>
<asp:TemplateField HeaderText="PLANQTY">
<ItemTemplate><asp:TextBox ID="txtplanqty" runat="server" BackColor="#ffffcc" OnTextChanged="txtplanqty\_TextChanged" AutoPostBack="true" Font-Size="x-Small" Text='<%# Eval("PLAN\_QTY") %>' Width="70px"></asp:TextBox> </ItemTemplate> </asp:TemplateField> <asp:TemplateField HeaderText="TRGT\_PRD"> <ItemTemplate> <asp:TextBox ID="txttrgtprd" runat="server" Font-Size="X-Small" onfocus="getdata(this)" OnTextChanged="txttrgtprd\_TextChanged" BackColor="#ffffcc" Width="70px" Text='<%# Eval("TRGT\_PRD") %>' AutoPostBack="true"></asp:TextBox> </ItemTemplate> </asp:TemplateField> </Columns> <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <RowStyle BackColor="#EFF3FB" /> <EditRowStyle BackColor="#2461BF" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
function getdata(obj)
{
var txt = document.getElementById(obj);
txt.value='0';
}note in the above snippet that you are passing a reference to the textbox (this) to the javascript method, hence you dont need the getElementById at all - you already have a reference to the element. therefore, your javascript method can simply be
function getdata(obj)
{
obj.value='0';
}or your textbox's onfocus could simply be:
onfocus="this.value='0';"