一.设计从gridview获取ID和NAME
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.IO;
namespace WebControlLibrary
{
[DefaultProperty("Text")]
[ToolboxData("<{0}:GetIDAndName runat=server></{0}:GetIDAndName>")]
public class GetIDAndName : CompositeControl //WebControl //, IPostBackEventHandler, IPostBackDataHandler
{
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("http://blog.csdn.net/zhanghefu/")]
[Localizable(true)]
[Description("The address of URL to open by the Button.")]
public string URL
{
get
{
String s = (String)ViewState["URL"];
return ((s == null) ? String.Empty : s);
}
set
{
ViewState["URL"] = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("0")]
[Localizable(true)]
[Description("To set the WindowWidth of URL which is opened by the Button.")]
public int WindowWidth
{
get
{
object o = ViewState["WindowWidth"];
if (o != null)
{
return int.Parse(ViewState["WindowWidth"].ToString());
}
else
{
return 0;
}
}
set
{
ViewState["WindowWidth"] = value;
}
}
[Bindable(true)]
[Category("Appearance")]
[DefaultValue("0")]
[Localizable(true)]
[Description("To set the WindowHeight of URL which is opened by the Button.")]
public int WindowHeight
{
get
{
object o = ViewState["WindowHeight"];
if (o != null)
{
return int.Parse(ViewState["WindowHeight"].ToString());
}
else
{
return 0;
}
}
set
{
ViewState["WindowHeight"] = value;
}
}
public TextBox TextBox;
public TextBox TextBox2;
//public HiddenField HiddenField;
public Button Button;
protected override void CreateChildControls()
{
TextBox = new TextBox();
TextBox2 = new TextBox();
//HiddenField = new HiddenField();
Button = new Button();
TextBox.ID = "txtName";
this.Controls.Add(TextBox);
TextBox2.ID = "txtID";
this.Controls.Add(TextBox2);
//HiddenField.ID = "hfID";
//HiddenField.Visible = true;
//this.Controls.Add(HiddenField);
Button.ID = "btnChoose";
Button.Text = "选择";
Button.Click += new EventHandler(Button_Click);
this.Controls.Add(Button);
}
public event GetNameAndIDEventHandler OpenDilog;
protected void Button_Click(object sender, EventArgs e)
{
try
{
if (URL == "" || URL ==null)
{
string strRemind = "The URL is not null.please input your URL!";
this.Page.RegisterStartupScript(System.Guid.NewGuid().ToString(),"<script>window.alert('" + strRemind + "')</script>");
}
//else
//{
// OpenDilog(this, new SuzsoftArgs(this.Page, URL, WindowWidth, WindowHeight));
//}
if (OpenDilog != null)
{
OpenDilog(this, new SuzsoftArgs(this.Page