<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Read GridView Contents using javascript</title>
<script type ="text/javascript" >
function rowno(rowindex)
{
alert(rowindex);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gv" runat="server" Font-Size="16pt"
Font-Names="Verdana" Width="292px" AutoGenerateColumns="False"
onrowediting="gv_RowEditing" onrowcancelingedit="gv_RowCancelingEdit"
onrowupdating="gv_RowUpdating" DataKeyNames="TKTNO"
onrowdatabound="gv_RowDataBound">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<Columns>
<asp:TemplateField HeaderText="TKTNO">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TKTNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BASIC">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("BASIC") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DA">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("DA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DP">
<ItemTemplate>
<asp:TextBox ID="txtdp" runat="server" Text='<%# Bind("DP") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AB">
<ItemTemplate>
<asp:TextBox ID="txtab" runat="server" Text='<%# Bind("AB") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WH">
<ItemTemplate>
<asp:TextBox ID="txtwh" runat="server" Text='<%# Bind("WH") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ED">
<ItemTemplate>
<asp:TextBox ID="txted" runat="server" Text='<%# Bind("ED") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="A_DAY">
<ItemTemplate>
<asp:TextBox ID="txta_day" runat="server" Text='<%# Bind("A_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="B_DAY">
<ItemTemplate>
<asp:TextBox ID="txtb_day" runat="server" Text='<%# Bind("B_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="C_DAY">
<ItemTemplate>
<asp:TextBox ID="txtc_day" runat="server" Text='<%# Bind("C_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D_DAY">
<ItemTemplate>
<asp:TextBox ID="txtd_day" runat="server" Text='<%# Bind("D_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" Font-Names="Verdana" Font-Size="X-Small" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" Font-Names="Verdana" Font-Size="X-Small" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" Font-Names="Verdana" Font-Size="X-Small" />
</asp:GridView>
<hr />
<asp:Button runat="server" ID="cmdRead" Text="Javascript to read gridview data" OnClientClick=" return Read_Data();" />
</div>
</form>
</body>
</html>
Code behind:-
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((TextBox)e.Row.FindControl("textbox")).Attributes.Add("OnChange", "javascript:rowno(" + e.Row.RowIndex + ")");
}
}
Thanks Shibashish Mohanty
<head id="Head1" runat="server">
<title>Read GridView Contents using javascript</title>
<script type ="text/javascript" >
function rowno(rowindex)
{
alert(rowindex);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="gv" runat="server" Font-Size="16pt"
Font-Names="Verdana" Width="292px" AutoGenerateColumns="False"
onrowediting="gv_RowEditing" onrowcancelingedit="gv_RowCancelingEdit"
onrowupdating="gv_RowUpdating" DataKeyNames="TKTNO"
onrowdatabound="gv_RowDataBound">
<RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
<SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
<Columns>
<asp:TemplateField HeaderText="TKTNO">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Bind("TKTNO") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NAME">
<ItemTemplate>
<asp:Label ID="Label2" runat="server" Text='<%# Bind("NAME") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="BASIC">
<ItemTemplate>
<asp:Label ID="Label3" runat="server" Text='<%# Bind("BASIC") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DA">
<ItemTemplate>
<asp:Label ID="Label4" runat="server" Text='<%# Bind("DA") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DP">
<ItemTemplate>
<asp:TextBox ID="txtdp" runat="server" Text='<%# Bind("DP") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="AB">
<ItemTemplate>
<asp:TextBox ID="txtab" runat="server" Text='<%# Bind("AB") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="WH">
<ItemTemplate>
<asp:TextBox ID="txtwh" runat="server" Text='<%# Bind("WH") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="ED">
<ItemTemplate>
<asp:TextBox ID="txted" runat="server" Text='<%# Bind("ED") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="A_DAY">
<ItemTemplate>
<asp:TextBox ID="txta_day" runat="server" Text='<%# Bind("A_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="B_DAY">
<ItemTemplate>
<asp:TextBox ID="txtb_day" runat="server" Text='<%# Bind("B_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="C_DAY">
<ItemTemplate>
<asp:TextBox ID="txtc_day" runat="server" Text='<%# Bind("C_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="D_DAY">
<ItemTemplate>
<asp:TextBox ID="txtd_day" runat="server" Text='<%# Bind("D_DAY") %>' Width="20px"></asp:TextBox>
</ItemTemplate>
</asp:TemplateField>
</Columns>
<PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" Font-Names="Verdana" Font-Size="X-Small" />
<HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" Font-Names="Verdana" Font-Size="X-Small" HorizontalAlign="Left" />
<AlternatingRowStyle BackColor="White" Font-Names="Verdana" Font-Size="X-Small" />
</asp:GridView>
<hr />
<asp:Button runat="server" ID="cmdRead" Text="Javascript to read gridview data" OnClientClick=" return Read_Data();" />
</div>
</form>
</body>
</html>
Code behind:-
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
((TextBox)e.Row.FindControl("textbox")).Attributes.Add("OnChange", "javascript:rowno(" + e.Row.RowIndex + ")");
}
}
Thanks Shibashish Mohanty
No comments:
Post a Comment
Please don't spam, spam comments is not allowed here.