** Here's the code
 using System;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using _911PigeonAlert.Controls;

namespace _911PigeonAlert
{
/// <summary>
/// Summary description for Search.
/// </summary>
public class Search : Functions
{
private SqlDataReader dataReader1;
private SqlCommand cmd1;
private string strCountry;
private string Url;
private System.Web.UI.WebControls.ImageButton ibtnEdit;

private FormControl fcDDLCountries = new FormControl();
private ListItem liDefault = new ListItem("Select", "");

protected System.Web.UI.HtmlControls.HtmlGenericControl spnConfirm;
protected System.Web.UI.HtmlControls.HtmlGenericControl spnEdit;
protected System.Web.UI.HtmlControls.HtmlGenericControl spnMain;
protected System.Web.UI.HtmlControls.HtmlGenericControl spnSearchRes;
protected System.Web.UI.WebControls.Button btnNewSearch;
protected System.Web.UI.WebControls.Button btnSearch;
protected System.Web.UI.WebControls.Button btnUpdate;
protected System.Web.UI.WebControls.DataGrid dgSearchRes;
protected System.Web.UI.WebControls.DropDownList ddlCountry;
protected System.Web.UI.WebControls.DropDownList ddlStates;
protected System.Web.UI.WebControls.Label lblErrorCity;
protected System.Web.UI.WebControls.Label lblErrorFirstName;
protected System.Web.UI.WebControls.Label lblErrorLastName;
protected System.Web.UI.WebControls.Label lblErrorState;
protected System.Web.UI.WebControls.Literal litConfirm;
protected System.Web.UI.WebControls.RadioButton rbEmail;
protected System.Web.UI.WebControls.RadioButton rbName;
protected System.Web.UI.WebControls.RadioButton rbPhone;
protected System.Web.UI.WebControls.TextBox txtCity;
protected System.Web.UI.WebControls.TextBox txtEmail;
protected System.Web.UI.WebControls.TextBox txtEmail2;
protected System.Web.UI.WebControls.TextBox txtFirstName;
protected System.Web.UI.WebControls.TextBox txtFirstName2;
protected System.Web.UI.WebControls.TextBox txtLastName;
protected System.Web.UI.WebControls.TextBox txtLastName2;
protected System.Web.UI.WebControls.TextBox txtPhone1;
protected System.Web.UI.WebControls.TextBox txtPhone2;
protected System.Web.UI.WebControls.TextBox txtPhone3;
protected System.Web.UI.WebControls.TextBox txtPhone4;
protected System.Web.UI.WebControls.TextBox txtPhone5;
protected System.Web.UI.WebControls.Label litErrorCountry;
protected System.Web.UI.HtmlControls.HtmlForm frmSearchRescuer;
protected System.Web.UI.WebControls.TextBox txtPhone6;

private void Page_Load(object sender, System.EventArgs e)
{
Initialize();
}

#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET <http://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.dgSearchRes.PageIndexChanged += new 
System.Web.UI.WebControls.DataGridPageChangedEventHandler(
this.DataGrid_Paging);
this.dgSearchRes.ItemDataBound += new 
System.Web.UI.WebControls.DataGridItemEventHandler(
this.DataGrid_ItemDataBound);
this.Load += new System.EventHandler(this.Page_Load);

}
#endregion

private void DataGrid_ItemDataBound(object sender, 
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if(e.Item.ItemType == ListItemType.Header)
{
e.Item.Cells[0].Text = "First Name";
e.Item.Cells[1].Text = "Last Name";
e.Item.Cells[2].Text = "Email";
e.Item.Cells[3].Text = "Phone";
e.Item.Cells[4].Text = "Edit";
}

if((e.Item.ItemType == ListItemType.Item) || (e.Item.ItemType == 
ListItemType.AlternatingItem))
{
int RescuerID;
DataRowView drv;
drv = (DataRowView) e.Item.DataItem;
RescuerID = (int) drv["RescuerID"];

ibtnEdit = (ImageButton) e.Item.Cells[4].Controls[1];
ibtnEdit.ID <http://ibtnEdit.ID> = "ibtnEdit" + RescuerID;
ibtnEdit.ToolTip = "Edit rescuer";
ibtnEdit.CommandArgument = RescuerID.ToString();
}
}

private void DataGrid_Paging(object sender, 
System.Web.UI.WebControls.DataGridPageChangedEventArgs e)
{
SetupDataGrid();
dgSearchRes.CurrentPageIndex = e.NewPageIndex;
BindData();
}

public void Initialize()
{
if(!(IsPostBack))
{
int MenuID = Convert.ToInt32(Request.QueryString["SubMenuID"]);
int GroupID = Convert.ToInt32(Session["GroupID"]);
SecurityCheck(MenuID, GroupID, false);

rbEmail.Attributes.Add("onclick", "ToggleSearch('Email');");
rbName.Attributes.Add("onclick", "ToggleSearch('Name');");
rbPhone.Attributes.Add("onclick", "ToggleSearch('Phone');");
}

Url = Request.Url.ToString();
}

private void BindData()
{
string proc = "";
string strEmail = txtEmail.Text;
string strFirstName = txtFirstName.Text;
string strLastName = txtLastName.Text;
string strPhone = txtPhone1.Text + txtPhone2.Text + txtPhone3.Text;

SqlConnection conn = new SqlConnection((string) Application["conn"]);

if(rbEmail.Checked)
{
proc = "SearchRescuerEmail";

cmd1 = new SqlCommand(proc, conn); 
cmd1.CommandType = CommandType.StoredProcedure;

SqlParameter p = new SqlParameter("@Email", strEmail);
p.Direction = ParameterDirection.Input;
cmd1.Parameters.Add(p);
}

if(rbName.Checked)
{
proc = "SearchRescuerName";

cmd1 = new SqlCommand(proc, conn); 
cmd1.CommandType = CommandType.StoredProcedure;

SqlParameter p1 = new SqlParameter("@FirstName", strFirstName);
p1.Direction = ParameterDirection.Input;
SqlParameter p2 = new SqlParameter("@LastName", strLastName);
p2.Direction = ParameterDirection.Input;
cmd1.Parameters.Add(p1);
cmd1.Parameters.Add(p2);
}

if(rbPhone.Checked)
{
proc = "SearchRescuerPhone";

cmd1 = new SqlCommand(proc, conn); 
cmd1.CommandType = CommandType.StoredProcedure;

SqlParameter p = new SqlParameter("@Phone", strPhone);
p.Direction = ParameterDirection.Input;
cmd1.Parameters.Add(p);
}

conn.Open();
dataReader1 = cmd1.ExecuteReader();

DataTable dt = new DataTable();

dt.Columns.Add(new DataColumn("RescuerID", System.Type.GetType("System.Int32
")));
dt.Columns.Add(new DataColumn("Email", System.Type.GetType("System.String
")));
dt.Columns.Add(new DataColumn("FirstName", System.Type.GetType("
System.String")));
dt.Columns.Add(new DataColumn("LastName", System.Type.GetType("System.String
")));
dt.Columns.Add(new DataColumn("Phone", System.Type.GetType("System.String
")));

if(dataReader1.HasRows)
{
while(dataReader1.Read())
{
DataRow dr = dt.NewRow();

dr[0] = dataReader1["RescuerID"];
dr[1] = dataReader1["Email"];
dr[2] = dataReader1["FirstName"];
dr[3] = dataReader1["LastName"];
dr[4] = dataReader1["Phone"];

dt.Rows.Add(dr);
}
}

dgSearchRes.DataSource = dt;
dgSearchRes.DataKeyField = "RescuerID";
dgSearchRes.DataBind();

dataReader1.Close();
conn.Close();
}

public void Country_IndexChange(object sender, EventArgs e)
{
string CountryID = ddlCountry.SelectedItem.Value;
string proc;

DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection((string) Application["conn"]);

proc = "SelectStates";
SqlCommand cmd2 = new SqlCommand(proc, conn); 
cmd2.CommandType = CommandType.StoredProcedure;
SqlParameter p = new SqlParameter("@CountryID", CountryID);
p.Direction = ParameterDirection.Input;
cmd2.Parameters.Add(p);

SqlDataAdapter adapter = new SqlDataAdapter(cmd2);
adapter.Fill(ds);

ddlStates.DataSource = ds.Tables[0];
ddlStates.DataTextField = ds.Tables
[0].Columns["Description"].ColumnName.ToString();
ddlStates.DataValueField = ds.Tables
[0].Columns["StateID"].ColumnName.ToString();
ddlStates.DataBind();
ddlStates.Items.Insert(0, liDefault);
}

public void EditRescuer_Click(object sender, 
System.Web.UI.ImageClickEventArgs e)
{
int RescuerID;
string strPhoneNum = "";
ImageButton ibtnEdit = (ImageButton) sender;
RescuerID = int.Parse(ibtnEdit.CommandArgument);
ViewState["RescuerID"] = RescuerID;

spnEdit.Visible = true;
spnConfirm.Visible = false;
spnMain.Visible = false;
spnSearchRes.Visible = false;

SqlDataReader dataReader2;
SqlConnection conn = new SqlConnection((string) Application["conn"]);

SetupCountryDropDown();
GetRescuerCountry();
SetupStateDropDown();

string proc = "EditRescuer";
SqlCommand cmd2 = new SqlCommand(proc, conn); 
cmd2.CommandType = CommandType.StoredProcedure;
SqlParameter p2 = new SqlParameter("@RescuerID", RescuerID);
p2.Direction = ParameterDirection.Input;
cmd2.Parameters.Add(p2);

conn.Open();
dataReader2 = cmd2.ExecuteReader();

if(dataReader2.HasRows)
{
while(dataReader2.Read())
{
if(!(System.Convert.IsDBNull(dataReader2["FirstName"])))
{
txtFirstName2.Text = (string) dataReader2["FirstName"];
}

if(!(System.Convert.IsDBNull(dataReader2["LastName"])))
{
txtLastName2.Text = (string) dataReader2["LastName"];
}

if(!(System.Convert.IsDBNull(dataReader2["Phone"])))
{
strPhoneNum = (string) dataReader2["Phone"];
StringBuilder sbPhone = new StringBuilder(strPhoneNum, 9);
sbPhone.Insert(3,",");
sbPhone.Insert(7,",");

Regex r = new Regex("(,)");
string [] s = r.Split(sbPhone.ToString());

txtPhone4.Text = s[0];
txtPhone5.Text = s[2];
txtPhone6.Text = s[4];
}

if(!(System.Convert.IsDBNull(dataReader2["Email"])))
{
txtEmail2.Text = (string) dataReader2["Email"];
}

if(!(System.Convert.IsDBNull(dataReader2["City"])))
{
txtCity.Text = (string) dataReader2["City"];
}

if(!(System.Convert.IsDBNull(dataReader2["Country"])))
{
foreach(ListItem item in ddlCountry.Items)
{
if(item.Value == (string) dataReader2["Country"])
item.Selected = true;
else
item.Selected = false;
}
}

if(!(System.Convert.IsDBNull(dataReader2["State"])))
{
foreach(ListItem item in ddlStates.Items)
{
if(Convert.ToInt32(item.Value) == (int) dataReader2["State"])
item.Selected = true;
else
item.Selected = false;
}
}
}
}

dataReader2.Close();
conn.Close();
}

private void GetRescuerCountry()
{
int RescuerID = (int) ViewState["RescuerID"];
string proc = "";
string strEmail = txtEmail.Text;
string strFirstName = txtFirstName.Text;
string strLastName = txtLastName.Text;
string strPhone = txtPhone1.Text + txtPhone2.Text + txtPhone3.Text;

SqlDataReader dataReader2;
SqlCommand cmd2;
SqlConnection conn = new SqlConnection((string) Application["conn"]);

proc = "GetRescuerCountry";

cmd2 = new SqlCommand(proc, conn); 
cmd2.CommandType = CommandType.StoredProcedure;

SqlParameter p = new SqlParameter("@RescuerID", RescuerID);
p.Direction = ParameterDirection.Input;
cmd2.Parameters.Add(p);

conn.Open();
dataReader2 = cmd2.ExecuteReader();

if(dataReader2.HasRows)
{
while(dataReader2.Read())
{
strCountry = (string) dataReader2["Country"];
}
}

dataReader2.Close();
conn.Close();
}

public void NewSearch_Click(object sender, EventArgs e)
{
Response.Redirect(Url);
}

public void SearchRescuer_Click(object sender, EventArgs e)
{
SetupDataGrid();
BindData();
}

private void SetupCountryDropDown()
{
fcDDLCountries.dsDropDownList(ddlCountry, (string) Application["conn"], 
"SelectCountries", "CountryID", "CountryID");
}

private void SetupStateDropDown()
{
DataSet ds = new DataSet();
SqlConnection conn = new SqlConnection((string) Application["conn"]);

string proc = "SelectStates";
SqlCommand cmd2 = new SqlCommand(proc, conn); 
cmd2.CommandType = CommandType.StoredProcedure;
SqlParameter p = new SqlParameter("@CountryID", strCountry);
p.Direction = ParameterDirection.Input;
cmd2.Parameters.Add(p);

SqlDataAdapter adapter = new SqlDataAdapter(cmd2);
adapter.Fill(ds);

ddlStates.DataSource = ds.Tables[0];
ddlStates.DataTextField = ds.Tables
[0].Columns["Description"].ColumnName.ToString();
ddlStates.DataValueField = ds.Tables
[0].Columns["StateID"].ColumnName.ToString();
ddlStates.DataBind();
}

private void SetupDataGrid()
{
spnSearchRes.Visible = true;
spnConfirm.Visible = false;
spnEdit.Visible = false;
spnMain.Visible = false;
dgSearchRes.HorizontalAlign = HorizontalAlign.Center;
dgSearchRes.Width = Unit.Pixel(350);
dgSearchRes.CssClass = "small";
dgSearchRes.BorderColor = Color.Black;
dgSearchRes.BorderWidth = Unit.Pixel(1);
dgSearchRes.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;
dgSearchRes.ItemStyle.HorizontalAlign = HorizontalAlign.Center;
dgSearchRes.HeaderStyle.BackColor = Color.Gray;
dgSearchRes.AlternatingItemStyle.BackColor = Color.LightGray;
dgSearchRes.AutoGenerateColumns = false;
dgSearchRes.AllowPaging = true;
dgSearchRes.PagerStyle.BackColor = Color.DarkGray;
dgSearchRes.PagerStyle.Mode = PagerMode.NumericPages;
dgSearchRes.PageSize = 15;
dgSearchRes.AllowSorting = false;
}

public void UpdateRescuer_Click(object sender, EventArgs e)
{
spnConfirm.Visible = true;
spnEdit.Visible = false;
spnMain.Visible = false;
spnSearchRes.Visible = false;

}
}
}


---------- Forwarded message ----------
From: Dean Fiala <[EMAIL PROTECTED]>
Date: Jun 7, 2005 7:19 PM
Subject: Re: [AspNetAnyQuestionIsOk] ImageButton
To: [email protected]

Let's see the code...

On 6/7/05, Ryan Olshan <[EMAIL PROTECTED]> wrote:
> I have a C# ASP.NET <http://asp.net/> <http://ASP.NET <http://asp.net/>> 
form that works the following way on 
> the same web form:
> 1) User searches for a person
> 2) Possible matches are displayed in a data grid with an ImageButton next 
to
> each match to edit that record
> The problem that you have to click the ImageButton two times before it
> shows the HTML span is visible where the person can be edited. On the 
first
> click the page just refreshes and the datagrid is still visible.
> The control is named ibtnEdit. If I use (!(ibtnEdit.Page.IsPostBack)) then
> on the second click it keeps reloading the page and shows the data grid.
> Any ideas?
> 
> --
> Thank you,
> Ryan Olshan
> TeraNet Systems
> http://www.teranetsystems.com
> 
> 
> [Non-text portions of this message have been removed]
> 
> 
> 
> 
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 


-- 
Dean Fiala
Very Practical Software, Inc
http://www.vpsw.com

------------------------------
*Yahoo! Groups Links*

   - To visit your group on the web, go to:
   http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
   - To unsubscribe from this group, send an email to:
   [EMAIL PROTECTED]<[EMAIL PROTECTED]>
   - Your use of Yahoo! Groups is subject to the Yahoo! Terms of
Service<http://docs.yahoo.com/info/terms/>.
   



-- 
Thank you,
Ryan Olshan
TeraNet Systems
http://www.teranetsystems.com


[Non-text portions of this message have been removed]



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to