Click here to Skip to main content
15,887,998 members

Comments by Faiz_Khan (Top 20 by date)

Faiz_Khan 23-Jun-12 2:32am View    
Following is the code im using fo navigating Gridview

var SelectedRow = null;
var SelectedRowIndex = null;
var UpperBound = null;
var LowerBound = null;

window.onload = function()
{
//UpperBound = 8;
LowerBound = 0;
SelectedRowIndex = -1;
}
function SelectRow(CurrentRow, RowIndex)
{
if(SelectedRow == CurrentRow || RowIndex > UpperBound || RowIndex < LowerBound)
return;

if(SelectedRow != null)
{
SelectedRow.style.backgroundColor = SelectedRow.originalBackgroundColor;
SelectedRow.style.color = SelectedRow.originalForeColor;
}

if(CurrentRow != null)
{
CurrentRow.originalBackgroundColor = CurrentRow.style.backgroundColor;
CurrentRow.originalForeColor = CurrentRow.style.color;
CurrentRow.style.backgroundColor = '#ff9933';
CurrentRow.style.color = 'Black';
}

SelectedRow = CurrentRow;
SelectedRowIndex = RowIndex;
if(SelectedRow !=null && SelectedRow != '' && SelectedRow != '0')
{
setTimeout("SelectedRow.focus();",0);
}
}

function SelectSibling(e)
{
if(SelectedRow !=null && SelectedRow != '' && SelectedRow != '0')
{
var e = e ? e : window.event;
var KeyCode = e.which ? e.which : e.keyCode;
UpperBound = parseInt(document.getElementById('<%=NoOfRow.ClientID %>').value) - 1;
if(KeyCode == 40)
SelectRow(SelectedRow.nextSibling, SelectedRowIndex + 1);
else if(KeyCode == 38)
SelectRow(SelectedRow.previousSibling, SelectedRowIndex - 1);
else if(KeyCode == 13)
{
var control = '<%=CurRow.ClientID %>';
document.getElementById(control).value = SelectedRowIndex;
document.getElementById('<%= btnAddFromGrid.ClientID %>').click();
}
return false;
}
}


protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
e.Row.TabIndex = -1;
e.Row.Attributes["onclick"] = string.Format("javascript:SelectRow(this, {0});", e.Row.RowIndex);
e.Row.Attributes["onkeydown"] = "javascript:return SelectSibling(event);";
e.Row.Attributes["onselectstart"] = "javascript:return false;";
}
}
private void FillGridBuyer(string pm)
{
Regex r = new Regex("[0-9]");
if (r.Match(pm).Success)
SqlQry = "SELECT Buyer_Id, Buyer_Name, Contact_Person, Branch FROM Buyer_Master WHERE (Branch = '" + Session["BRANCH"].ToString() + "') and Buyer_code like '%" + pm + "%'";

OF.FillGrid_Without_SP(GVBUY, SqlQry);
NoOfRow.Value = GVBUY.Rows.Count.ToString();
HFNameOfGrid.Value = "GVBUY";
}
Now the Problem is unless i click the Gridview the SelectedRow and SelectedRow.nextSibling will not get.
Faiz_Khan 23-Jun-12 2:21am View    
Deleted
Following is the code im using fo navigating Gridview

var SelectedRow = null;
var SelectedRowIndex = null;
var UpperBound = null;
var LowerBound = null;

window.onload = function()
{
//UpperBound = 8;
LowerBound = 0;
SelectedRowIndex = -1;
}
function SelectRow(CurrentRow, RowIndex)
{
if(SelectedRow == CurrentRow || RowIndex > UpperBound || RowIndex < LowerBound)
return;

if(SelectedRow != null)
{
SelectedRow.style.backgroundColor = SelectedRow.originalBackgroundColor;
SelectedRow.style.color = SelectedRow.originalForeColor;
}

if(CurrentRow != null)
{
CurrentRow.originalBackgroundColor = CurrentRow.style.backgroundColor;
CurrentRow.originalForeColor = CurrentRow.style.color;
CurrentRow.style.backgroundColor = '#ff9933';
CurrentRow.style.color = 'Black';
}

SelectedRow = CurrentRow;
SelectedRowIndex = RowIndex;
if(SelectedRow !=null && SelectedRow != '' && SelectedRow != '0')
{
setTimeout("SelectedRow.focus();",0);
}
}

function SelectSibling(e)
{
if(SelectedRow !=null && SelectedRow != '' && SelectedRow != '0')
{
var e = e ? e : window.event;
var KeyCode = e.which ? e.which : e.keyCode;
UpperBound = parseInt(document.getElementById('<%=NoOfRow.ClientID %>').value) - 1;
if(KeyCode == 40)
SelectRow(SelectedRow.nextSibling, SelectedRowIndex + 1);
else if(KeyCode == 38)
SelectRow(SelectedRow.previousSibling, SelectedRowIndex - 1);
else if(KeyCode == 13)
{
var control = '<%=CurRow.ClientID %>';
document.getElementById(control).value = SelectedRowIndex;
document.getElementById('<%= btnAddFromGrid.ClientID %>').click();
}
return false;
}
}


protected void GridView_RowCreated(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && (e.Row.RowState == DataControlRowState.Normal || e.Row.RowState == DataControlRowState.Alternate))
{
e.Row.TabIndex = -1;
e.Row.Attributes["onclick"] = string.Format("javascript:SelectRow(this, {0});", e.Row.RowIndex);
e.Row.Attributes["onkeydown"] = "javascript:return SelectSibling(event);";
e.Row.Attributes["onselectstart"] = "javascript:return false;";
}
}



private void FillGridBuyer(string pm)
{
Regex r = new Regex("[0-9]");
if (pm == "All")
SqlQry = "SELECT Buyer_Id, Buyer_Name, Contact_Person, Branch FROM Buyer_Master WHERE (Branch = '" + Session["BRANCH"].ToString() + "')";
else
if (r.Match(pm).Success)
SqlQry = "SELECT Buyer_Id, Buyer_Name, Contact_Person, Branch FROM Buyer_Master WHERE (Branch = '" + Session["BRANCH"].ToString() + "') and Buyer_code like '%" + pm + "%'";
else
SqlQry = "SELECT Buyer_Id, Buyer_Name, Contact_Person, Branch FROM Buyer_Master WHERE (Branch = '" + Session["BRANCH"].ToString() + "') and Buyer_Name like '%"
Faiz_Khan 18-Jun-12 7:04am View    
I'll pray for ur aircraft pilot’s license, :)
Faiz_Khan 18-Jun-12 6:51am View    
yes its working
thanks a lot dear
Faiz_Khan 18-Jun-12 6:43am View    
k, ..hope it works