Strange Behavior

G

Guest

Good morning, everyone.

Here is the strange behavior:

I have a datagrid (dgPIs) with paging enabled. When I click to view any
page in the grid, it runs the private void lnkIPReg method, instead of the
private void IPchangePage.

The lnkIPReg method refers to a linkbutton that I created in the grid. The
datagrid properties list the ItemCommand = lnkIPReg and the PageIndexChange
= IPchangePage.

Below are the methods mentioned. Can someone tell me what I am missing?

Thanks


private void IPchangePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgIPs.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}

private void lnkIPReg(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string ip = "";

ip = e.Item.Cells[9].Text;
Response.BufferOutput = true;
Response.Redirect("http://ws.arin.net/whois/?queryinput=" + ip);
 
G

Guest

ok..I can't seem to attach a file to this post, so, I just copied and pasted
the cs file.

using System;
using System.Configuration;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Web;
using System.Web.Security;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

namespace SalesApp
{
/// <summary>
/// Summary description for AccessMethod.
/// </summary>
public class logcred : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Label Label2;
protected System.Web.UI.WebControls.Label Label1;
protected System.Web.UI.WebControls.Label Label4;
protected System.Web.UI.WebControls.Panel Panel;
protected System.Web.UI.WebControls.DataGrid dgIPs;
protected System.Web.UI.WebControls.Label Label3;
protected System.Web.UI.WebControls.DataGrid dgLogCred;
protected System.Web.UI.WebControls.Label Label5;
protected System.Web.UI.WebControls.HyperLink hyperSearch;
protected System.Web.UI.WebControls.HyperLink hyperBugzilla;
protected System.Web.UI.WebControls.HyperLink hyperViewCustomers;
protected System.Web.UI.WebControls.DataGrid dgRefURLs;

private void Page_Load(object sender, System.EventArgs e)
{
dgIPs.ItemDataBound += new DataGridItemEventHandler(this.Item_Bound_IP);
dgRefURLs.ItemDataBound += new
DataGridItemEventHandler(this.Item_Bound_Ref);
dgLogCred.ItemDataBound +=new
DataGridItemEventHandler(this.Item_Bound_UP);

bindGrid();
}

private void Item_Bound_Ref(Object sender, DataGridItemEventArgs e)
{
//hide cust_id field
e.Item.Cells[2].Visible=false;
}

private void Item_Bound_UP(Object sender, DataGridItemEventArgs e)
{
//hide cust_id field
e.Item.Cells[6].Visible=false;
}

private void Item_Bound_IP(Object sender, DataGridItemEventArgs e)
{
//hide cust_id field
e.Item.Cells[10].Visible=false;

//store IP Segment 2 Start and End in variable
string ip2se = "";
//store IP Segment 3 Start and End in variable
string ip3se = "";
//store IP Segment 4 Start and End in variable
string ip4se = "";
{
if(e.Item.Cells[3].Text == e.Item.Cells[4].Text)
ip2se = e.Item.Cells[3].Text + ".";
else
ip2se = e.Item.Cells[3].Text + "-" + e.Item.Cells[4].Text + ".";
}
{
if(e.Item.Cells[5].Text == e.Item.Cells[6].Text)
ip3se = e.Item.Cells[5].Text + ".";
else
ip3se = e.Item.Cells[5].Text + "-" + e.Item.Cells[6].Text + ".";
}
{
if(e.Item.Cells[7].Text == e.Item.Cells[8].Text)
ip4se = e.Item.Cells[7].Text;
else
ip4se = e.Item.Cells[7].Text + "-" + e.Item.Cells[8].Text;
}
//hide the IP segments start and end octates
e.Item.Cells[2].Visible=false; //IP seg 1
e.Item.Cells[3].Visible=false; //IP seg 2 start
e.Item.Cells[4].Visible=false; //IP seg 2 end
e.Item.Cells[5].Visible=false; //IP seg 3 start
e.Item.Cells[6].Visible=false; //IP seg 3 end
e.Item.Cells[7].Visible=false; //IP seg 4 start
e.Item.Cells[8].Visible=false; //IP seg 4 end

{
//checks that data in the cell is not the value of the header or footer
to compare values
if(e.Item.ItemType !=ListItemType.Header &&
e.Item.ItemType!=ListItemType.Footer)

//formats and concatenate the ip segments into one cell
e.Item.Cells[9].Text = e.Item.Cells[2].Text + "." + ip2se + ip3se +
ip4se;
}
}

private void bindGrid()
{
int custid = Int32.Parse(Request.Params["cust_id"]);

SqlConnection conn = new SqlConnection
(ConfigurationSettings.AppSettings["SqlConnectionString"]);

conn.Open();

//fills the login credentials grid

SqlCommand dataCommandUP = new SqlCommand();
dataCommandUP.Connection = conn;
SqlDataAdapter adapterUP = new SqlDataAdapter(dataCommandUP);
SqlParameter paramUP = dataCommandUP.Parameters.Add ("@cust_id",
SqlDbType.Int, 4);
paramUP.Value = custid;
dataCommandUP.CommandText = "SELECT GEM.customers.name AS [Institution
Name], " +
"GEM.contacts.name_first AS [Contact First Name], " +
"GEM.contacts.name_last AS [Contact Last Name], " +
"GEM.config_usernames.username AS Username, " +
"GEM.config_usernames.password AS Password, " +
"GEM.customers.cust_id AS [GEM Customer ID] " +
"FROM GEM.customers INNER JOIN GEM.config_usernames ON " +
"GEM.customers.cust_id = GEM.config_usernames.cust_id INNER JOIN " +
"GEM.contacts ON GEM.config_usernames.contact_id =
GEM.contacts.contact_id " +
"WHERE GEM.customers.cust_id = @cust_id";

DataSet dsUP = new DataSet();

adapterUP.Fill(dsUP);
dgLogCred.DataSource = dsUP;
dgLogCred.DataBind();



//fills the IP grid
SqlCommand dataCommandIP = new SqlCommand();
dataCommandIP.Connection = conn;
SqlDataAdapter adapterIP = new SqlDataAdapter(dataCommandIP);
SqlParameter paramIP = dataCommandIP.Parameters.Add ("@cust_id",
SqlDbType.Int, 4);
paramIP.Value = custid;
dataCommandIP.CommandText = "SELECT GEM.customers.name as [Institution
Name], " +
"GEM.config_ip_addrs.ip_seg_1 AS [IP Seg. 1], " +
"GEM.config_ip_addrs.ip_seg_2_start AS [IP Seg. 2 Start], " +
"GEM.config_ip_addrs.ip_seg_2_end AS [IP Seg. 2 End], " +
"GEM.config_ip_addrs.ip_seg_3_start AS [IP Seg. 3 Start], " +
"GEM.config_ip_addrs.ip_seg_3_end AS [IP Seg. 3 End], " +
"GEM.config_ip_addrs.ip_seg_4_start AS [IP Seg. 4 Start], " +
"GEM.config_ip_addrs.ip_seg_4_end AS [IP Seg. 4 End], " +
"GEM.config_ip_addrs.cidr_block AS [IP Block], " +
"GEM.customers.cust_id FROM GEM.config_usernames " +
"INNER JOIN GEM.customers ON " +
"GEM.config_usernames.cust_id = GEM.customers.cust_id INNER JOIN " +
"GEM.config_ip_addrs ON " +
"GEM.customers.cust_id = GEM.config_ip_addrs.cust_id " +
"WHERE (GEM.customers.cust_id = @cust_id) ORDER BY
GEM.config_ip_addrs.ip_seg_1";


DataSet dsIP = new DataSet();

adapterIP.Fill(dsIP);
Cache["CustomerIPs"] = dsIP;
dsIP = (DataSet)Cache["CustomerIPs"];
dgIPs.DataSource = dsIP;
dgIPs.DataBind();

//fills the Referring URLs grid
SqlCommand dataCommandRefURLs = new SqlCommand();
dataCommandRefURLs.Connection = conn;
SqlDataAdapter adapterRefURLs = new SqlDataAdapter(dataCommandRefURLs);
SqlParameter paramRefURLs = dataCommandRefURLs.Parameters.Add
("@cust_id", SqlDbType.Int, 4);
paramRefURLs.Value = custid;

dataCommandRefURLs.CommandText = "SELECT GEM.customers.name AS
[Institution Name]," +
"GEM.config_referrers.http_referrer AS [Referring URL], " +
"GEM.customers.cust_id " +
"FROM GEM.customers INNER JOIN GEM.config_usernames ON " +
"GEM.customers.cust_id = GEM.config_usernames.cust_id INNER JOIN " +
"GEM.config_referrers ON " +
"GEM.customers.cust_id = GEM.config_referrers.cust_id " +
"WHERE (GEM.customers.cust_id = @cust_id)";

DataSet dsRefURLs = new DataSet();

adapterRefURLs.Fill(dsRefURLs);
dgRefURLs.DataSource = dsRefURLs;
dgRefURLs.DataBind();

conn.Close();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.dgLogCred.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.cmdSubs);
this.dgIPs.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.lnkIPReg);
this.dgIPs.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.IPchangePage);
this.dgIPs.ItemDataBound += new
System.Web.UI.WebControls.DataGridItemEventHandler(this.Item_Bound_IP);
this.dgRefURLs.PageIndexChanged += new
System.Web.UI.WebControls.DataGridPageChangedEventHandler(this.refChangePage);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion


private void refChangePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgRefURLs.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}

private void IPchangePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgIPs.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}

private void cmdSubs(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
if (e.CommandName.Equals("cmdSubs"))

Server.Transfer("subscriptions.aspx?cust_id=" +
e.CommandArgument.ToString());
}

private void lnkIPReg(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string ip = "";

ip = e.Item.Cells[9].Text;
Response.BufferOutput = true;
Response.Redirect("http://ws.arin.net/whois/?queryinput=" + ip);
}
}
}


chanmm said:
Attach you cs file. Not enough info.

chanmm

Antonio said:
Good morning, everyone.

Here is the strange behavior:

I have a datagrid (dgPIs) with paging enabled. When I click to view any
page in the grid, it runs the private void lnkIPReg method, instead of the
private void IPchangePage.

The lnkIPReg method refers to a linkbutton that I created in the grid.
The
datagrid properties list the ItemCommand = lnkIPReg and the
PageIndexChange
= IPchangePage.

Below are the methods mentioned. Can someone tell me what I am missing?

Thanks


private void IPchangePage(object source,
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
dgIPs.CurrentPageIndex = e.NewPageIndex;
bindGrid();
}

private void lnkIPReg(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string ip = "";

ip = e.Item.Cells[9].Text;
Response.BufferOutput = true;
Response.Redirect("http://ws.arin.net/whois/?queryinput=" + ip);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top