| | |
GridView cell textbox.Visible = true
Please support our ASP.NET advertiser: Intel Parallel Studio Home
![]() |
Hi all, I have a gridview in my project.
There is a cell that contains a dropdownlist, textbox and button.
My task is when the use clicks "others" in the dropdownlist, the textbox and button should show so that they can add new value into the dropdownlist.
But I got an exception.
"Object reference not set to an instance of an object. " at tbxName.Visible = true
How can I show that?
Please help.
There is a cell that contains a dropdownlist, textbox and button.
My task is when the use clicks "others" in the dropdownlist, the textbox and button should show so that they can add new value into the dropdownlist.
But I got an exception.
"Object reference not set to an instance of an object. " at tbxName.Visible = true
How can I show that?
Please help.
ASP.NET Syntax (Toggle Plain Text)
protected void ddlName_SelectedIndexChanged(object sender, EventArgs e) { DropDownList dropDown = sender as DropDownList; int selectedIndex = dropDown.SelectedIndex; GridViewRow gvr = dropDown.NamingContainer as GridViewRow; // GridViewRow gvr = (GridViewRow)gv_retrieve.Rows[index]; DropDownList ddl = gvr.FindControl("ddlName") as DropDownList; if (ddl.SelectedValue == "others") { TextBox tbxName = (TextBox)gv_retrieve.FindControl("tbxName") as TextBox; tbxName.Visible = true; } }
Serene Joey
Sorry sorry~~ I managed to do it already! it's my careless mistake. but then,
now the problem is i have to click twice at my button then the value in the textbox will be added.
is it i have to add something in page_load()?
below is my code.
and this is my aspx.
please help. thanks~
now the problem is i have to click twice at my button then the value in the textbox will be added.
is it i have to add something in page_load()?
below is my code.
ASP.NET Syntax (Toggle Plain Text)
protected void ddlName_SelectedIndexChanged(object sender, EventArgs e) { DropDownList dropDown = sender as DropDownList; int selectedIndex = dropDown.SelectedIndex; GridViewRow gvr = dropDown.NamingContainer as GridViewRow; DropDownList ddl = gvr.FindControl("ddlName") as DropDownList; if (ddl.SelectedValue == "others") { gvr.FindControl("tbxName").Visible = true; gvr.FindControl("btnAddName").Visible = true; } else { gvr.FindControl("tbxName").Visible = false; gvr.FindControl("btnAddName").Visible = false; } } protected void gv_retrieve_RowCommand(object sender, GridViewCommandEventArgs e) { //add name if (e.CommandName == "addName") { int index = Convert.ToInt32(e.CommandArgument); GridViewRow gvr = (GridViewRow)gv_retrieve.Rows[index]; if (gvr.RowType == DataControlRowType.DataRow) { if (DataControlRowState.Edit > 0 && gvr.RowState > 0) { DropDownList ddl = gvr.FindControl("ddlName") as DropDownList; TextBox tbx = (TextBox)gvr.FindControl("tbxName") as TextBox; if (ddl != null) { if (tbx.Text != "") { //check if name exist if (shareDAO.isNameExist(tbx.Text) == false) { ddl.Items.Add(tbx.Text); shareDAO.insertName(tbx.Text); ddl.SelectedValue = tbx.Text; gvr.FindControl("tbxName").Visible = false; gvr.FindControl("btnAddName").Visible = false; } else { Response.Write("<Script language=javascript>alert('Approval Party Name already exist!')</Script>"); } } } } } } // end of adding name }
and this is my aspx.
ASP.NET Syntax (Toggle Plain Text)
<asp:TemplateField HeaderText="Name"> <EditItemTemplate> <asp:DropDownList ID="ddlName" runat="server" Width="172px" DataSourceID="names" AppendDataBoundItems = "true" DataTextField="names" OnSelectedIndexChanged="ddlName_SelectedIndexChanged" AutoPostBack="True"> <asp:ListItem Text = "------------"></asp:ListItem> <asp:ListItem Text = "Others" Value ="others" ></asp:ListItem> </asp:DropDownList><br /> <asp:TextBox ID="tbxName" runat="server" Visible = "false" AutoPostBack="True"> </asp:TextBox> <asp:Button ID="btnAddName" runat="server" Text="Add" Visible="false" CommandName="addName" CommandArgument="<%# Container.DataItemIndex %>" />
please help. thanks~
Serene Joey
![]() |
Other Threads in the ASP.NET Forum
- Previous Thread: copy a project to another computer
- Next Thread: display values from one page to another page
| Thread Tools | Search this Thread |
.net 2.0 3.5 ajax alltypeofvideos appliances asp asp.net beginner box browser businesslogiclayer button c# cac checkbox class commonfunctions compatible content contenttype control countryselector courier dataaccesslayer database datagrid datagridview datalist deployment development dgv dialog dropdownlist dropdownmenu dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv gridview gudi iis javascript list listbox login menu microsoft mouse mssql nameisnotdeclared news novell numerical opera order panelmasterpagebuttoncontrols problem radio ratings redirect registration relationaldatabases reportemail schoolproject search security serializesmo.table sessionvariables silverlight smoobjects software sql sql-server sqlserver2005 ssl tracking treeview validatedate validation vb.net videos vista visual-studio visualstudio vs2008 web webapplications webarchitecture webdevelopment webprogramming webservice wizard xsl youareanotmemberofthedebuggerusers





