Hi friends,
please help me to resolve the folloowing issue.
i have 2 pages, in first page html checkbox and dropdown list controls
are there inside the datagrid control and i need to move values from
one page(first.aspx) to another(second.aspx) page. if i check the
checkboxes then press submit button it is working gud with my code.
but i press the Back button of the Browser in 2nd page(second.aspx)
has to be uncheck all the checkboxes in the grid has to uncheck the
datagrid checkboxes by using javascript in the first.aspx page
private void btnSubmit_Click(object sender, System.EventArgs e)
{
DataSet dscourse=(DataSet)ViewState["ds"];
DataSet selected = ((DataSet)ViewState["ds"]).Clone() ;
string total = lblTotalPrice.Text;
foreach (DataGridItem dgItem in dgExtendCourse.Items)
{
HtmlInputCheckBox chkclick =
(HtmlInputCheckBox)dgItem.FindControl
("chkselect");
Label lblcource =
(Label)dgItem.FindControl("lblCourseName");
Label
lblDays_Left=(Label)dgItem.FindControl("lblDaysLeft");
if (chkclick.Checked==true)
{
foreach (DataRow row in
dscourse.Tables[0].Rows)
{
if
(row["coursename"].ToString() == lblcource.Text && row
["DaysLeft"].ToString()==lblDays_Left.Text)
{
selected.Tables[0].ImportRow(row);
}
}
}
}
if (selected.Tables != null &&
selected.Tables[0].Rows.Count > 0)
{
Session["selectedrow"] = selected;
Session["totalprice"] =
HidenTotal.Value.ToString();
Response.Redirect("courseExtension.aspx");
}
}
protected void dgExtendCourse_ItemDataBound(object sender,
DataGridItemEventArgs e)
{
if (e.Item.ItemIndex >= 0)
{
DropDownList ddlDuration = (DropDownList)
e.Item.FindControl("ddlduration");
Label lblPrice = (Label)e.Item.FindControl
("lblExtPrice");
Label lblinitialPrice = (Label)e.Item.FindControl
("lblstandardPrice");
HtmlInputCheckBox chkclick = (HtmlInputCheckBox)
e.Item.FindControl("chkselect");
chkclick.Attributes.Add("onclick", "CheckBxChange
(this," + ddlDuration.ClientID + "," + lblPrice.ClientID + "," +
lblTotalPrice.ClientID + "," + lblinitialPrice.ClientID + ",1)");
ddlDuration.Attributes.Add("onchange", "OnChangeValue
(this," + lblPrice.ClientID + "," + lblTotalPrice.ClientID
+","+lblinitialPrice.ClientID + ")");
}
}
JavaScript:
<script language="javascript" type="text/javascript">
var TotalChkBx;
var Counter;
var HeaderID;
window.onload = function()
{
TotalChkBx = parseInt('<%=
this.dgExtendCourse.Items.Count %>');
HeaderID ='';
Counter = 0;
tempcounter=0;
totalcost=0;
}
var intID;
function HeaderClick(CheckBox)
{
var TargetBaseControl =
document.getElementById('<%=
this.dgExtendCourse.ClientID %>');
var TargetChildControl = "chkselect";
var Inputs =
TargetBaseControl.getElementsByTagName("input");
if(CheckBox.checked==true)
{
tempcounter=0;
var
totallbl=document.getElementById("lblTotalPrice");
totallbl.innerText=0;
}
else
tempcounter=TotalChkBx;
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;
var chk=Inputs[n];
chk.onclick();
}
Counter = CheckBox.checked ? TotalChkBx : 0;
}
function OnChangeValue(dropdown,price,total,standardPrice)
{
var myindex = dropdown.selectedIndex;
var SelValue = dropdown.options[myindex].value;
var intial=price.innerText;
if(SelValue==30)
{
price.innerText=standardPrice.innerText*1;
}
if(SelValue==60)
{
price.innerText=standardPrice.innerText*2;
}
if(SelValue==90)
{
price.innerText=standardPrice.innerText*3;
}
// alert(total.innerText);
// if( total.innerText!=null )
total.innerText=parseInt(total.innerText)+(parseInt
(price.innerText)-parseInt(intial));
// else
// total.innerText=(parseInt(price.innerText)-
parseInt(intial));
var hidden1=document.getElementById
("HidenTotal");
hidden1.value=total.innerText;
return true;
}
function CheckBxChange
(obj,ddl,price,total,standardPrice,value)
{
if(price.innerText=='' || price.innerText==null)
price.innerText='0';
if (obj.checked == true)
{
ddl.disabled=false;
tempcounter++;
total.innerText=parseInt(total.innerText)
+parseInt(price.innerText)
if(tempcounter==TotalChkBx)
{
// alert('equal');
var TargetBaseControl = document.getElementById
('<%= this.dgExtendCourse.ClientID %>');
var TargetChildControl = "chkAll";
var Inputs =
TargetBaseControl.getElementsByTagName
("input");
Inputs[0].checked = true;
}
}
else
{
ddl.disabled=true;
total.innerText=parseInt(total.innerText)-
parseInt(price.innerText)
tempcounter--;
var TargetBaseControl = document.getElementById
('<%= this.dgExtendCourse.ClientID %>');
var TargetChildControl = "chkAll";
var Inputs =
TargetBaseControl.getElementsByTagName
("input");
Inputs[0].checked = false;
if(tempcounter==0)
{
total.innerText=0;
}
}
var hidden1=document.getElementById
("HidenTotal");
hidden1.value=total.innerText;
}
</script>