how can i write this code from aspx page in code behind?
<img src="http://download.skype.com/share/skypebuttons /buttons/call_blue_white_124x52.png" style="border: none;" width="124" height="52" alt="Skype Me™!" />
thanks
Place a PlaceHolder control in the Page where you want this to appear.
Then write
PlaceHolder1.Controls.Add(New LiteralControl("<img src=\"http://download.skype.com/share/skypebuttons/buttons/call_blue_white_124x52.png\" style=\"border: none;\" width=\"124\" height=\"52\" alt=\"Skype Me™!\" />"));
Hopes you are using C#
Edit
If you are looking to add dynamically, then place the above place holder and then use below.
HyperLink hyp=new HyperLink();
hyp.ID="hyp1";
hyp.ImageUrl="http://download.skype.com/share/skypebuttons/buttons/call_blue_white_124x52.png";
hyp.NavigateUrl="skype:MySkype?call";
hyp.Text="Skype Me™!" ;
hyp.ToolTip="Skype Me™!";
hyp.Target="_new";
PlaceHolder1.Controls.Add(hyp);
if you're going to create a DataTable for GridView and add all column names and datas from codebehind and need to rearrange some of columns (like adding hyperlinks or etc.) i think this might be useful.
for my situation i need to rearrange my rows' cells like that (currently i have 6 cells, and want to change 6. value)
in gridview's RowDataBound event
string myVariable = e.Row.Cells[0].Text;//i'm getting value from index number 0
HyperLink hp = new HyperLink();
hp.NavigateUrl = String.Format("some_aspx_page.aspx?myVariable={0}", myVariable);
hp.Text = "Link name";
e.Row.Cells[5].Controls.Add(hp); //and add to index number 5
Related
I'm populating a gridview using a table and there is column which holds link IDs.
There can by many link IDs in the same cell.
If the cell contains one link ID then it works fine. The challenge is to support arbitrary number of links on the same cell.
My code:
<asp:HyperLinkField DataNavigateUrlFields="CWEID"
DataNavigateUrlFormatString="https://cwe.mitre.org/data/definitions/{0}.html"
DataTextField="CWEID" HeaderText="CWE ID" Target="_blank"/>
The cell value retrieved from table can be: [770\n838\n120], thus the cell should show 3 links for each ID.
I searched around, and it seems we can do it statically but not for arbitrary number of links.
Any pointers on how to accomplish this?
My suggestion is to replace HyperLinkField with TemplateField and nested Repeater inside.
There is example :
<asp:TemplateField HeaderText="CWE ID">
<ItemTemplate>
<asp:Repeater runat="server" ID="rptLinks" DataSource='<%# Eval("CWEID").ToString.Replace("\n", "").Split(" ")%>'>
<ItemTemplate>
<%# Container.DataItem%>
<br />
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:TemplateField>
Repeater will split CWEID (with \n, I think that is vbCrLf in vb.net so You can replace \n with vbCrLf, without double quotes) record and place all links in separated <a href.... You'll get all links in that cell. There is no matter how many links are stored into CWEID (one or more).
So, result will be (for example) :
770<br>
838<br>
120<br>
Ot just one link, depend how many links You have in CWEID.
UPDATE :
Code changed for DataSource to <%# Eval("CWEID").ToString.Replace("\n", " ").Split(" ")%>
You could add a handler to the gridview's RowDataBound event. In that event you have the ability to modify the contents of any of the cells being rendered in the current row of the gridview, including the ability to create new HTML elements and insert them. In the code below I'm adding an icon to the first cell in a gridview if the current row has child data to be shown.
'New Bootstrap style toggle button for details view
Dim toggle As New HtmlGenericControl("i")
With toggle
.Attributes("class") = "icon-plus icon-white"
.Attributes("onclick") = "javascript: gvrowtoggle(" & e.Row.RowIndex + (e.Row.RowIndex + 2) & ")"
.Attributes("id") = "toggleBttn"
End With
Then I append the new control to the first cell in the current row:
e.Row.Cells(0).Controls.Add(toggle)
I have set a dynamic gridview, which i want to use it in another form so i created it as
public GridView gv = new GridView()
i have set in Page_Load properties of gv to
gv.AutoGenerateColumns = true;
gv.Visible = true;
then i have another grid MyGridView which is static and have data in it. So when i try to copy all static gridview data to dynamic gridview data that is
gv.DataSource = MyGridView.DataSource;
gv.DataBind();
I am not able to view the Grid gv, why is it so? someone told me to add
'Controls.Add(gv) in Page_Load
when i added its showing compile time error, that gv should be in a form with runat=server.
How can i put a dynamic gridview into a form with runat=server?
So my requirement is gv should be visible, how can i achieve this?
Thanks in advance.
you need to use some sort of holders for this try pannel
on aspx page create
<asp:Panel id="panel1" runat="server"></asp:Panel>
on your backednd
do
panel1.Controls.Add(gv)
Place a div with runat="server" into your page
then:
YourDivID.Controls.Add(gv)
I have one Listbox named "List1" and one button says "Append".
I have on textbox named "TextDescription".
I want to put the select values from the listbox to textbox on click of append button.
So can anyone tell me how to do this?
You could use the .val() function. So assuming you have a select with id="myselect" and a text input with id="mytext" you could do this:
var values = $('#myselect').val();
if (values != null) {
// concatenate the selected values with , so that we can add them to the textbox
$('#mytext').val(values.join(','));
}
And here's a live demo illustrating it in action.
I have a label and I want to add to it a link.
I want to use javascript like :
MyLabel.Attributes.Add("`onclick`", "javascript:`SOME_CODE`")
What must I add in (SOME_CODE) to redirect the user to another link.
Thanks.
Have you tried: window.location = 'http://google.com' ?
Are the any particular reason you want to use Javascript for this, and not just the HyperLink Control?
Update:
You can either use a normal a-tag link or use the ASP.Net HyperLink control:
This is the markup:
<asp:HyperLink ID="MyHyperLinkControl" NavigateUrl="http://google.com" runat="server" />
This is if you want to add it from the code-behind:
HyperLink link = new HyperLink();
link.NavigateUrl = "http://google.com";
parentControl.Controls.Add(link);
Where parentControl, is the container you want to add it to, for instance a cell in a table or a panel.
See here for more information on how to add a control to a panel
Just use a plain anchor tag (<a >), but put the label inside the anchor (the reverse is not strictly valid html). If you don't want it to show up as a link every time, you can accomplish that by omitting the href attribute. This is easy to do with a normal <asp:HyperLink> server control like so:
<asp:HyperLink id="..." runat="server"><asp:Label ... ></asp:Label></asp:HyperLink>
Now, the href attribute will only render if you actually set the NavigateUrl property in your code. You might also find that using an <asp:HyperLink> completely replaces the need for the label.
<a href="http://google.com" >Go to Google</a>
If this has anything to do with your previous question, use a Hyperlink control instead of a Label:
Dim Hyperlink1 As New Hyperlink
Hyperlink1.Text = "XYZ"
Hyperlink1.NavigateUrl = "http://www.google.com"
Dim Literal1 As New Literal
Literal1.Text = "<br />"
' Add the control to the placeholder
PlaceHolder1.Controls.Add(Hyperlink1)
PlaceHolder1.Controls.Add(Literal1)
I have a gridview for which I am binding data from a Generic List collection. Currently not connected to DB. All the columns in the GridView are defined as properties(get;set.
I want to have tooltip on one of the columns. The column has a very big description. I want to show only 3 words in the column and the rest of the description should appear in tooltip.
Currently my gridview has only asp:gridview id and runat server
There are no columns, headertemplate and itemtemplate.
Could anyone suggest some idea on this.
Thanks in advance
Well, I don't know how you are getting your columns in place...but I suppose you could put a Label webcontrol in the itemtemplate for the header of each column, and give that label's tooltip property the value you want it to have.
Seems to me like that would be a pretty viable solution for this, if I'm understanding you correctly..
You can use an itme template with a label as mentioned. Bind the label the full description:
<ItemTemplate>
<asp:Label id="l1" runat="server" Text='<%# Eval("Description")' />
</ItemTemplate>
In code-behind, use RowDataBound to process each row accordingly:
protected void RowDB(..)
{
Label l = e.Row.Cells[4].Controls[1] as Label;
if (l == null) return;
string description = l.Text;
l.Text = //Partial text here
}
And the grid will bind each row, the full text is passed to a variable, and you can insert a substring of the text (3 words or such) by assigning the new value to the text property.
What kind of tooltip are you looking for? You could use the tooltip property, or consider using the ACT HoverMenuExtender: http://www.asp.net/AJAX/AjaxControlToolkit/Samples/HoverMenu/HoverMenu.aspx