Home > other >  How to add ASP.NET control for <i></i> tags in Html and assign them inside .FindControl(
How to add ASP.NET control for <i></i> tags in Html and assign them inside .FindControl(

Time:05-25

Does anyone knows How to add ASP.NET control for <i></i> tags?
i am looking for ASP.NET Control that is equivalent with <i> Html tag

in my case, I also want to implement .FindControl() method for it inside the .cs file.
Here's the part of the code..


Example.axcs

<asp:Panel id="forDiv" CssClass="input-group colorpicker-component" runat="server">
                        <asp:TextBox ID="txtHeree"  runat="server" Style="width: auto"></asp:TextBox>
                        <asp:Panel CssClass="input-group-append" runat="server">
                            <asp:Label CssClass="input-group-addon input-group-text" runat="server"><i></i></asp:Label>
                        </asp:Panel>
</asp:Panel>


from the code above, the FindControl method that I have implemented goes like this,


Example.ascx.cs

TextBox txtVal = e.Row.FindControl("txtHeree") as TextBox;
Panel txtVal = e.Row.FindControl("forDiv") as Panel;

and, etc..


My current problem is, I still can't find both the equivalent ASP.NET Control for <i></i> tags and also for .FindControl() method for it.
sure, I have read the reference to another QnA forum from both Stackoverflow and Microsoft Docs:
enter image description here

And say we use a gridview, repeater etc.?

say this markup, we just dropped in that (wiht id, and runat=server).

Quite much makes that control work, look, and feel like any other server side asp.net control.

Say, this markup and gridview (for the find control example).

        <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
            DataKeyNames="ID" CssClass="table" >
            <Columns>
                <asp:TemplateField HeaderText="Hotel Name"> <ItemTemplate>
                        <asp:Label ID="txtHotel" runat="server" Text='<%# Eval("HotelName") %>' ></asp:Label>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="City"> <ItemTemplate>
                        <asp:Label ID="txtCity" runat="server" Text='<%# Eval("City") %>' ></asp:Label>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="Description"> <ItemTemplate>
                        <i id="Descript" runat="server"> <%# Eval("Description") %>  </i>
                    </ItemTemplate> </asp:TemplateField>

                <asp:TemplateField HeaderText="View"> <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="View" 
                        CssClass="btn" OnClick="Button1_Click" />
                    </ItemTemplate> </asp:TemplateField>

            </Columns>
        </asp:GridView>

Code to load:

   protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GridView1.DataSource = General.MyRst("SELECT * FROM tblHotelsA ORDER BY HotelName");
            GridView1.DataBind();
        }
    }

And we have this now:

enter image description here

And our view button click code, say this:

    protected void Button1_Click(object sender, EventArgs e)
    {
        Button btn = sender as Button;
        GridViewRow gRow = btn.NamingContainer as GridViewRow;

        int? PKID = GridView1.DataKeys[gRow.RowIndex]["ID"] as int?;

        Debug.Print("pk data base row id = "   PKID.ToString());
        Debug.Print("Row click index = "   gRow.RowIndex);

        // get hotel name
        Label txtHotel = gRow.FindControl("txtHotel") as Label;
        Debug.Print("Hotel name = "   txtHotel.Text);

        // get our <i> guy
        HtmlGenericControl myIthing = gRow.FindControl("Descript") as HtmlGenericControl;
        Debug.Print("Our i guy = "   myIthing.InnerText);

    }

Output :

enter image description here

so, most such controls - adding a "id" and runat="server", and at that point, it quite much behaves like most other asp.net controls.

  • Related