简体   繁体   中英

Dynamic textbox ID in .aspx.cs

I have a question on C#. I use the GridView ItemTemplate to add a textbox to a whole column. I add the ID to the drop down list in ItemTemplate. Therefore, the generated ID of drop down list is 'GridViewID_dropdownListID_number' in each row when I launch the project.

However, I cannot set the drop down list to .Visible = true and .Visible = false in .aspx.cs file. I try to type the 'dropdownListID' and 'GridViewID_dropdownListID_number' to 'Page_Load' function. However, it displays the error message which is under light the statement.

'The name 'GridViewID_dropdownListID_0' does not exist in the current content'

Can I set the drop down list visible to true and false in .aspx.cs?

PS I can retrieve the row number by GridViewRow

Here is an example how to do this in the item template of a repeater -- this is typically how this problem is solved:

<asp:DataList Runat="server" ...>
    <ItemTemplate>
        <asp:Label runat="Server" Text='<%# Container.DataItem("data") %>'
                    Visible='<%# Container.DataItem("makevisible") %>'/>
    </ItemTemplate>
</asp:DataList>

您可以使用FindControl

DropdownLIst tvSeries = (DropdownLIst)tableOfTVSeries.Rows[0].Cells[2].FindControl("tvSeriesTableCategoryDropdownLIst");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM