I have a GridView with two updatable fields. but both of field update together. this is my code:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White" BorderColor="#CCCCCC" BorderStyle="None" BorderWidth="1px" CellPadding="3"
DataSourceID="SqlDataSrcAddMark" HorizontalAlign="Center" Font-Names="Tahoma" Width="729px" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:TemplateField HeaderText="AttendanceStatus" SortExpression="AttendanceStatus" ItemStyle-Width="200px" HeaderStyle-CssClass="Header-center">
<ItemTemplate>
<asp:HiddenField runat="server" ID="hfStatus" Value='<%# Eval("ExamAttendanceTypeId") %>' />
<asp:Label ID="lblStatus" runat="server" Text='<%# Eval("ExamAttendanceTypeId").ToString() == "False" ? "غایب" : "حاضر" %>'></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Value="1">Present</asp:ListItem>
<asp:ListItem Value="2">Unacceotable Absent</asp:ListItem>
<asp:ListItem Value="3">Acceptable Absent</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mark" SortExpression="Mark" ItemStyle-Width="200px" HeaderStyle-CssClass="Header-center">
<ItemTemplate>
<asp:Label ID="lbl_Text1" runat="server" Text='<%# Bind("Mark") %>'></asp:Label>
<asp:TextBox ID="txt_Text1" runat="server" Text='<%# Bind("Mark") %>' CssClass="hideControl"
AutoPostBack="true" OnTextChanged="Change"></asp:TextBox>
</ItemTemplate>
<HeaderStyle CssClass="Header-center" />
</asp:TemplateField>
<asp:BoundField DataField="LastName" HeaderText="نام خانوادگی" SortExpression="LastName" HeaderStyle-CssClass="Header-center">
<HeaderStyle CssClass="Header-center"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="FirstName" HeaderText="نام " SortExpression="FirstName" HeaderStyle-CssClass="Header-center">
<HeaderStyle CssClass="Header-center"></HeaderStyle>
</asp:BoundField>
<asp:BoundField DataField="SubjectStudyLessonCourseId" HeaderText="-----" SortExpression="SubjectStudyLessonCourseId" HeaderStyle-CssClass="Header-center">
<HeaderStyle CssClass="Header-center"></HeaderStyle>
</asp:BoundField>
</Columns>
<FooterStyle BackColor="White" ForeColor="#000066" />
<HeaderStyle BackColor="#006699" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="White" ForeColor="#000066" HorizontalAlign="Left" />
<RowStyle ForeColor="#000066" />
<SelectedRowStyle BackColor="#669999" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#F1F1F1" />
<SortedAscendingHeaderStyle BackColor="#007DBB" />
<SortedDescendingCellStyle BackColor="#CAC9C9" />
<SortedDescendingHeaderStyle BackColor="#00547E" />
</asp:GridView>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$('[id*=GridView1] tr td').on('click', function () {
$('[id*=GridView1] tr td').each(function () {
if ($(this).index() <= 1) {
$(this).find('span').show();
$(this).find('select').hide();
$(this).find('input[type=text]').hide();
$(this).find('span').html($(this).find('input[type=text]').val());
}
});
var val = $(this).find('span').html();
$(this).find('span').hide();
$(this).find('select').show();
$(this).find('input[type=text]').val(val);
$(this).find('input[type=text]').show();
$(this).find('input[type=text]').focus();
});
$("[id*=DropDownList1]").on('change', function () {
var status = $(this).val();
if (status == "1") {
$(this).closest('tr').find('[id*=lblStatus]').html("Present");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
else if (status == "2") {
$(this).closest('tr').find('[id*=lblStatus]').html("Unacceptable Absent");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
else {
$(this).closest('tr').find('[id*=lblStatus]').html("Acceptable Absent");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
});
});
</script>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string status = (e.Row.FindControl("hfStatus") as HiddenField).Value;
if (status == "1")
{
(e.Row.FindControl("lblStatus") as Label).Text = "Present";
}
else if (status == "2")
{
(e.Row.FindControl("lblStatus") as Label).Text = "Unacceptable Absent";
}
else
{
(e.Row.FindControl("lblStatus") as Label).Text = "Acceptable Absent";
}
}
}
in this code both of MArk field and Attendance field will update together and the change function writes for Mark field. But I want if the user changes the value of each field that field updated after change value.
for this action I change my code like below but I faced to error:
<script type="text/javascript">
$(function () {
$('[id*=GridView1] tr td').on('click', function () {
$('[id*=GridView1] tr td').each(function () {
if ($(this).index() <= 1) {
$(this).find('span').show();
$(this).find('select').hide();
$(this).find('input[type=text]').hide();
$(this).find('span').html($(this).find('input[type=text]').val());
}
});
var val = $(this).find('span').html();
$(this).find('span').hide();
$(this).find('select').show();
$(this).find('input[type=text]').val(val);
$(this).find('input[type=text]').show();
$(this).find('input[type=text]').focus();
});
$("[id*=DropDownList1]").on('change2', function () {
var status = $(this).val();
if (status == "1") {
$(this).closest('tr').find('[id*=txt_Text2]').html("حاضر");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
else if (status == "2") {
$(this).closest('tr').find('[id*=txt_Text2]').html("غیبت غیرمجاز");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
else {
$(this).closest('tr').find('[id*=txt_Text2]').html("غیبت مجاز");
$(this).closest('tr').find('[id*=hfStatus]').val(status);
}
});
});
</script>
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
string status = (e.Row.FindControl("hfStatus") as HiddenField).Value;
if (status == "1")
{
(e.Row.FindControl("txt_Text2") as Label).Text = "حاضر";
}
else if (status == "2")
{
(e.Row.FindControl("txt_Text2") as Label).Text = "غیبت غیرمجاز";
}
else
{
(e.Row.FindControl("txt_Text2") as Label).Text = "غیبت مجاز";
}
}
}
this is an error:
how can I fix this problem and update both of two field separate?