在ASP.NET 2.0中,引入了MasterPage的机制,在当前页使用MasterPage的情况下,放在 ContentPlaceholder1这样的内容页的控件无法用Page.FindControl MSDN对FindControl的解释:在当前的命名容器中搜索带指定 id 参数的服务器控件 这里有一篇文章阐述阐述FindControl方法和INamingContainers接口:http://www.odetocode.com 譬如当有GridView存在的话,GridView其实也是一个naming container,要找GridView中的一个ControlID,就不能用Page.FindControl,而得用[GridView 对象].FindControl方法。 很多时候,因为是动态控件,明知道是在同一个naming container中,但不知道该naming container是什么对象,一个控件要找到另一个控件,可以用this.Parent.FindControl
(“LB_edit”)).Visible = false; ((LinkButton)GV_Main.Rows[rowIndex].FindControl(“LB_upd”)). [rowIndex].FindControl(“lbl_ctrq”)).Visible = false; ((TextBox)GV_Main.Rows[rowIndex].FindControl = false; ((LinkButton)GV_Main.Rows[rowIndex].FindControl(“LB_cancel”)).Visible = false; ((Label)GV_Main.Rows[rowIndex].FindControl(“lbl_chanpin”)).Visible = true; (( [rowIndex].FindControl(“lbl_ctrq”)).Visible = true; ((TextBox)GV_Main.Rows[rowIndex].FindControl
("ContentPlaceHolder2"); Label m3Label = (Label)cpMaster2.FindControl("Master3_Label"); ("ContentPlaceHolder2"); Label m3Label = (Label)cpMaster2.FindControl("Master3_Label"); ("ContentPlaceHolder1"); Label m2Label = (Label)cpMaster1.FindControl("Master2_Label"); ("ContentPlaceHolder1"); Label m2Label = (Label)cpMaster1.FindControl("Master2_Label"); Button5_Click(object sender, EventArgs e) { Label mLabel = (Label)Master.Master.Master.FindControl
("lblSex"); LinkButton lbupdate = (LinkButton)e.Item.FindControl("update"); LinkButton lbdelete = (LinkButton)e.Item.FindControl("delete"); if (lblsex! == ListItemType.AlternatingItem) { HiddenField hf = (HiddenField)e.Item.FindControl ("hfid"); Repeater rpchild = (Repeater)e.Item.FindControl("childRepeater"); ("hfidchild"); Repeater rpgrantchild = (Repeater)e.Item.FindControl("grantchildRepeater
e.Row.Attributes["style"] = "Cursor:hand"; //问题分类下拉框绑定选中值 if (((DropDownList)e.Row.FindControl = null) { DropDownList ddlProVar = (DropDownList)e.Row.FindControl("ddlProVar") ; SetSelectedItem(ddlProVar, ((HiddenField)e.Row.FindControl("hdProVarState")).Value);
GridView1.DataBind(); sqlcon.Close(); } ========================================= 我已经通过FindControl if (e.Row.RowType == DataControlRowType.DataRow) { e.Row.Cells[ 1 ].FindControl ( “ GridView2 “ ); } } 可是在FindControl(“GridView2”)后只有一个DataBind()方法,并没有DataSource ——————————————————– GridView GRTemp=(GridView)e.Row.Cells[1].FindControl(“GridView2”); GRTemp.DataSource DataRowView rowv = (DataRowView)e.Row.DataItem; Label lblCareer = (Label)e.Row.FindControl
case "-3": int p = Convert.ToInt32(((DropDownList)codeTable.BottomPagerRow.FindControl ((Label)codeTable.BottomPagerRow.FindControl("pageNumber")).Text = PageIndex + ""; ((Label )codeTable.BottomPagerRow.FindControl("totalNumber")).Text = PageCount + ""; ? for (int i = 1; i <= PageCount; i++) ((DropDownList)codeTable.BottomPagerRow.FindControl int p = Convert.ToInt32(((DropDownList)codeTable.BottomPagerRow.FindControl("pageList")).SelectedValue
e.Item.ItemType == ListItemType.AlternatingItem)) { //string classname = ((Button)e.Item.FindControl .Text; DataRowView drv = (DataRowView)e.Item.DataItem; Repeater rptProductList = (Repeater)e.Item.FindControl e.Item.ItemType == ListItemType.AlternatingItem)) { //string classname = ((Button)e.Item.FindControl (“gDel”)).Text; DataRowView drv = (DataRowView)e.Item.DataItem; Image image = (Image)e.Item.FindControl goodsImg”); image.ImageUrl = drv[“cContentImg”].ToString(); Label label = (Label)e.Item.FindControl
ContentPlaceHolder,来访问其中的控件(此时已为第二层) ContentPlaceHolder cpMaster1 = (ContentPlaceHolder)Master.Master.FindControl ("ContentPlaceHolder1"); Label m2Label = (Label)cpMaster1.FindControl("Master2_Label"); ("ContentPlaceHolder1"); Label m2Label = (Label)cpMaster1.FindControl("Master2_Label"); protected void Button3_Click(object sender, EventArgs e) { Label mLabel = (Label)Master.Master.FindControl protected void Button4_Click(object sender, EventArgs e) { Label mLabel = (Label)Master.Master.FindControl
GridView1_RowDataBound( object sender, GridViewRowEventArgs e) { if (((DropDownList)e.Row.FindControl = null ) { DropDownList ddlxueli = (DropDownList)e.Row.FindControl // // 选中 DropDownList ddlxueli.SelectedValue = ((HiddenField)e.Row.FindControl ( " TBCard " )).Text; string xueli = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl ( " DDLXueli " )).SelectedValue; string price = ((TextBox)GridView1.Rows[e.RowIndex].FindControl
GridViewRow row in GridView1.Rows) { // 从GridView中的TextBox控件得到文本 string textBoxText = ((TextBox)row.FindControl Response.Write(textBoxText); // 从GridView中的DropDownLis控件得到选定值 string dropDownListText = ((DropDownList)row.FindControl SelectedItem.Value; Response.Write(dropDownListText); // 从GridView中的ListBox控件选择值 ListBox myListBox = (ListBox)row.FindControl Response.Write(selectedItem.Value); } } } 以上代码中我们做过的都是使用GridViewRow对象来循环访问 GridView控件中的所有行,下一步我们将使用FindControl
object sender, GridViewUpdateEventArgs e) { FileUpload fileUpload = GridView1.Rows[e.RowIndex].FindControl When you have the instance of the GirdView’s row, you can use the FindControl method to locate the FileUpload FindControl("FileUpload1") as FileUpload; fileUpload.SaveAs(System.IO.Path.Combine("C:""", fileUpload.FileName _Inserting(object sender, ObjectDataSourceMethodEventArgs e) { FileUpload upload = DetailsView1.FindControl
== -1) 25 { 26 //设置性别 27 RadioButtonList rbl = e.Row.FindControl int id = Convert.ToInt32(this.gv.DataKeys[e.RowIndex].Value); 172 string name = (gvr.Cells[0].FindControl ).SelectedValue; 174 string country = (gvr.Cells[2].FindControl("ddlCountry") as DropDownList ("tbxName") as TextBox).Text; 200 string sex = (tr.Cells[0].FindControl("rblSex") as RadioButtonList ).SelectedValue; 201 string country = (tr.Cells[0].FindControl("ddlCountry") as DropDownList)
= ((DataRowView)e.Item.DataItem).Row[“au_id”].ToString(); Repeater repeaterSub = (Repeater)e.Item.FindControl string au_id = ((DataRowView)e.Item.DataItem).Row[“id”].ToString(); CheckBox chk = (CheckBox)e.Item.FindControl meun_role r on ur.roleid=r.id “ + “where u.id=” + au_id; Repeater repeaterSub = (Repeater)e.Item.FindControl i = 0; i < this.group_manage.Items.Count; i++) { CheckBox chk = (CheckBox)group_manage.Items[i].FindControl
ListItemType.AlternatingItem) { DataList childs = (DataList)e.Item.FindControl strFirstNo = rows["bigid"].ToString(); Label l = (Label)e.Item.FindControl parent.Items.Count; i++) { DataList myDataList = (DataList)parent.Items[i].FindControl myDataList.Items.Count; j++) { CheckBox myCheckBox = (CheckBox)myDataList.Items[j].FindControl
btn_Click); } void btn_Click(object sender, EventArgs e) { Label lbl = (Label)this.FindControl EventTest1_myClick(object sender, EventArgs e) { Label lbl = (Label)EventTest1.FindControl void btn_Click(object sender, EventArgs e) { Label lbl = (Label)this.FindControl( public void RaisePostBackEvent(string Index) { Label lbl = (Label)this.FindControl 由现有的控件的事件触发 void btn_Click(object sender, EventArgs e) { Label lbl = (Label)this.FindControl
将新增的记录更新到数据库中去 void Button1_Click(object sender, EventArgs e) { TextBox customerID = Gridview1.FooterRow.FindControl ("CustomerIDTextBox") as TextBox; TextBox companyName = Gridview1.FooterRow.FindControl("CompanyNameTextBox ") as TextBox; DropDownList ContactTitle = Gridview1.FooterRow.FindControl("ContactTitleDropDownList" ("TextBox2")).Text; SqlDataSource1.UpdateParameters[1].DefaultValue = ((TextBox)row.Cells[1].FindControl ("TextBox2")).Text.Replace("’", "’’"); string value2 = ((TextBox)row.Cells[1].FindControl("TextBox3")
-1) 18 { 19 //设置性别 20 RadioButtonList rbl = e.Row.FindControl [1].Selected = true; 39 //国籍 40 DropDownList ddlCountry = e.Row.FindControl li); 50 } 51 //兴趣 52 CheckBoxList cbl = e.Row.FindControl ") as RadioButtonList).SelectedValue; 92 string Country = (this.gv.Rows[this.gv.EditIndex].FindControl new System.Text.StringBuilder(); 94 foreach (ListItem li in (this.gv.Rows[this.gv.EditIndex].FindControl
)e.Item.DataItem).Row["ID"].ToString();//获得对应ID Repeater repeater= (Repeater)e.Item.FindControl ("users_list");//找到要绑定数据的Repeater //Literal Lit = ((Literal)e.Item.FindControl("Lit_cn ")); //Literal Lit_remark = ((Literal)e.Item.FindControl("Lit_remark"));
GridView1.Rows[i]; SqlDataSource1.UpdateParameters[0].DefaultValue = ((TextBox)row.Cells[0].FindControl TextBox2")).Text; SqlDataSource1.UpdateParameters[1].DefaultValue = ((TextBox)row.Cells[1].FindControl GridViewRow row = GridView1.Rows[i]; string value1 = ((TextBox)row.Cells[0].FindControl ("TextBox2")).Text.Replace("'","''"); string value2 = ((TextBox)row.Cells[1].FindControl