Hello,
I have created a checkbox and textbox template fields in gridview and i have xml data source. as i click the button then the checked corresponding checkboxes the current date and time will appear into the respective textboxes
here is the HTML code which i have tried
<%
@ Page Language="C#" AutoEventWireup="true" CodeFile="BarcodeGen.aspx.cs" Inherits="BarcodeGen" %>
<!
DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml" >
<
head runat="server">
<title>Untitled Page</title>
<link href="gridview.css" rel="stylesheet" type="text/css" />
<script language=javascript>
function
SelectAllCheckboxes(spanChk){
// Added as ASPX uses SPAN for checkbox
var
oItem = spanChk.children;
var
theBox=(spanChk.type=="checkbox")?spanChk:spanChk.children.item[0];
xState=theBox.checked;
elm=theBox.form.elements;
for
(i=0;i<elm.length;i++)
if
(elm[i].type=="checkbox" && elm[i].id!=theBox.id)
{
//elm[i].click();
if
(elm[i].checked!=xState)
elm[i].click();
//elm[i].checked=xState;
}
}
</
script>
<%
--<script type="text/javascript">
var TotalChkBx;
var Counter;
window.onload = function()
{
//Get total no. of CheckBoxes in side the GridView.
TotalChkBx = parseInt('<%= this.gvCheckboxes.Rows.Count %>');
//Get total no. of checked CheckBoxes in side the GridView.
Counter = 0;
}
function HeaderClick(CheckBox)
{
//Get target base & child control.
var TargetBaseControl =
document.getElementById('<%= this.gvCheckboxes.ClientID %>');
var TargetChildControl = "chkBxSelect";
//Get all the control of the type INPUT in the base control.
var Inputs = TargetBaseControl.getElementsByTagName("input");
//Checked/Unchecked all the checkBoxes in side the GridView.
for(var n = 0; n < Inputs.length; ++n)
if(Inputs[n].type == 'checkbox' &&
Inputs[n].id.indexOf(TargetChildControl,0) >= 0)
Inputs[n].checked = CheckBox.checked;
//Reset Counter
Counter = CheckBox.checked ? TotalChkBx : 0;
}
function ChildClick(CheckBox, HCheckBox)
{
//get target control.
var HeaderCheckBox = document.getElementById(HCheckBox);
//Modifiy Counter;
if(CheckBox.checked && Counter < TotalChkBx)
Counter++;
else if(Counter > 0)
Counter--;
//Change state of the header CheckBox.
if(Counter < TotalChkBx)
HeaderCheckBox.checked = false;
else if(Counter == TotalChkBx)
HeaderCheckBox.checked = true;
}
</script>--
%>
</
head>
<
body>
<form id="form1" runat="server">
<div>
<table cellspacing="5" style="width: 190px; border-right: black 1px solid; border-top: black 1px solid; border-left: black 1px solid; border-bottom: black 1px solid;">
<tr>
<td style="width: 97px">
</td>
</tr>
<tr>
<td style="width: 97px">
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" CssClass="grid-view"
DataSourceID="XmlDataSource1" Width="190px" CellPadding="4" ForeColor="#333333" GridLines="None" AllowPaging="True" PageSize="5" OnRowDataBound="GridView1_RowDataBound" OnSelectedIndexChanged="GridView1_SelectedIndexChanged1" OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanging="GridView1_SelectedIndexChanging">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkbox1" runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Left" VerticalAlign="Top" Width="20px" BorderColor="Black" BorderWidth="1px" />
<ItemStyle HorizontalAlign="Left" VerticalAlign="Top" Width="20px" BorderColor="Black" BorderWidth="1px" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader" onclick="javascript:SelectAllCheckboxes(this);" runat="server" />
</HeaderTemplate>
<FooterStyle BorderColor="Black" BorderWidth="1px" />
</asp:TemplateField>
<asp:BoundField DataField="MRN" HeaderText="MRN" SortExpression="MRN" >
<ItemStyle BorderColor="Black" BorderWidth="1px" Height="40px" />
<HeaderStyle BorderColor="Black" BorderWidth="1px" />
<FooterStyle BorderColor="Black" BorderWidth="1px" />
</asp:BoundField>
<asp:TemplateField HeaderText="SID">
<ItemTemplate>
<asp:TextBox ID="TextBox1" runat="server" Width="100px" />
</ItemTemplate>
<ItemStyle BorderColor="Black" BorderWidth="1px" />
<HeaderStyle BorderColor="Black" BorderWidth="1px" />
<FooterStyle BorderColor="Black" BorderWidth="1px" />
</asp:TemplateField>
<asp:TemplateField HeaderText="SID">
<ItemTemplate>
<asp:Image ID="Imgae1" runat="server" Height="50px" Width="200px" />
</ItemTemplate>
<ItemStyle BorderColor="Black" BorderWidth="1px" />
<HeaderStyle BorderColor="Black" BorderWidth="1px" />
<FooterStyle BorderColor="Black" BorderWidth="1px" />
</asp:TemplateField>
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<RowStyle BackColor="#EFF3FB" CssClass="normal" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" CssClass="alternate" />
</asp:GridView>
<%
--<asp:GridView ID="gvCheckboxes" runat="server"
AutoGenerateColumns="False" OnRowCreated="gvCheckboxes_RowCreated" Width="179px" DataSourceID="XmlDataSource1" CellPadding="4" CssClass="grid-view" ForeColor="#333333" GridLines="None">
<Columns>
<asp:TemplateField HeaderText="Select">
<ItemTemplate>
<asp:CheckBox ID="chkBxSelect" runat="server" />
</ItemTemplate>
<HeaderStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<ItemStyle HorizontalAlign="Center" VerticalAlign="Middle" Width="50px" />
<HeaderTemplate>
<asp:CheckBox ID="chkBxHeader"
onclick="javascript:HeaderClick(this);" runat="server" />
</HeaderTemplate>
</asp:TemplateField>
<asp:BoundField DataField="MRN" HeaderText="MRN" SortExpression="MRN" />
<asp:BoundField DataField="Date" HeaderText="Date" SortExpression="Date" />
</Columns>
<RowStyle BackColor="#EFF3FB" />
<AlternatingRowStyle BackColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
</asp:GridView>--
%>
<asp:XmlDataSource ID="XmlDataSource1" runat="server" DataFile="~/App_Data/Barcode.xml">
</asp:XmlDataSource>
<asp:TextBox ID="TextBox1" runat="server" ReadOnly="True"></asp:TextBox></td>
</tr>
<tr>
<td style="width: 97px; height: 14px;" align="left" valign="top">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click1" Text="Button" />
<asp:Button ID="Button2" runat="server" OnClick="Button2_Click2" Text="Button" /></td>
</tr>
<tr>
<td align="left" style="width: 97px; height: 14px" valign="top">
</td>
</tr>
</table>
</div>
</form>
</
body>
</
html>
Butto