Wednesday, August 10, 2011

Item databound in RadGrid

protected void RGUserDisplay_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
{
try
{
if (e.Item is GridDataItem)
{

GridDataItem gridDataItem = (GridDataItem)e.Item;

GridDataItem item = (GridDataItem)e.Item;
// Get the Linkbutton for Edit Button
LinkButton lnkEditButton = item.FindControl("rglnk_Edit") as LinkButton;

if(lnkEditButton != null)
{
lnkEditButton.Attributes.Add("onClick", "OpenQuestionModelPopup('" + this.popup_page.ClientID + "')");
}

//AdminModule objAdminModule = new AdminModule();
//string auid = "15";
//objAdminModule.DeleteRole(auid);

//LblSno.Text = intSerialNo.ToString();

/* if (strStatusText.ToLower() == "inactive")
{
imgControl.ImageUrl = Server.MapPath("Images/Red.gif");
imgControl.ToolTip = "Inactive";
}
else if (strStatusText.ToLower() == "active")
{
imgControl.ImageUrl = Server.MapPath("Images/Green.jpg");
imgControl.ToolTip = "active";

}*/
//intSerialNo++;
//ViewState["SNo"] = intSerialNo;
}

if (e.Item is GridHeaderItem)
{
GridHeaderItem gridHeaderItem = (GridHeaderItem)e.Item;

if (gridHeaderItem != null)
{
//==========Find the checkbox control in header and add an attribute=============
CheckBox chkAll = (CheckBox)gridHeaderItem.FindControl("chkCheckAll");
chkAll.Attributes.Add("onclick", "javascript:checkAll(this)");
}

}
}
catch (Exception ex)
{

using (objErrorLogs = new ErrorLogs())
{
objErrorLogs.Save_ErrorLog(this.AppRelativeVirtualPath.Replace(this.AppRelativeTemplateSourceDirectory, ""), MethodInfo.GetCurrentMethod().Name, ex.Message);
}
}

}

Traverse GridView row

foreach (GridViewRow row in gvPrivileges.Rows)
{
foreach (TableCell cell in row.Cells)
{
CheckBox chkBox = cell.FindControl("chkRoleId") as CheckBox;
if (chkBox != null)
{
if (chkBox.Checked == true)
{
if (!listRoles.Contains(int.Parse(chkBox.ToolTip)))
{
listRoles.Add(int.Parse(chkBox.ToolTip));
}
}
}
}


}

Friday, August 5, 2011

Calling the Server method from javascript

1. <script language="javascript">

function callserver() {
var tic = $get("txtNoOfTic").value;
// PageMethods.IsTicketAvailable(tic, OnSuccess, OnFailure);
// here tic is parameter passing to the server method
PageMethods.MyMethod(tic, OnSuccess, OnFailure);

}

function OnSuccess(result) {
if (result) {
alert(result);
$get("txtNoOfTic").select();
}
}

function OnFailure(error) {

alert('failture');
}

</script>

[WebMethod]
public static String MyMethod(string s)
{

return "Welcome";
}

2. Add the WebMethod attribute above the method
3. Add the namespace "using System.Web.Services;"

Showing a PopUp window using Javascript and Div tag


<div id="popup_page" style="border: 1px;position:fixed; background-position:center; top: 15%; left: 20%;border:1px solid #000;z-index: 69; border-style: solid;width: 600px; height: 400px;display:none;background-color: #E2EAFF;" runat="server">






Login


</div>
function OpenQuestionModelPopup(fld) {

try {
var pnlSecurtityQues = document.getElementById(fld);
var height = window.innerHeight;
var width = window.innerWidth;

if (pnlSecurtityQues) {
pnlSecurtityQues.style.display = "block";
pnlSecurtityQues.style.left = (width - 800) / 2 - (pnlSecurtityQues.style.width / 2) + "px";
pnlSecurtityQues.style.position = "fixed";
pnlSecurtityQues.style.top = (height - 400) / 2 - (pnlSecurtityQues.style.height / 2) + "px";
pnlSecurtityQues.style.zIndex = 11;
}
return false;
}
catch (e) {
}
}