Wednesday, September 28, 2011

How to clear dropdownlist OnSelectedIndexChanged in asp.net c#

<asp:DropDownList ID="ddlCity" runat="server" DataValueField="Id" DataTextField="Name"
OnSelectedIndexChanged="ddlCity_SelectedIndexChanged" AutoPostBack="true" >
 </asp:DropDownList>

protected void ddlCountry_SelectedIndexChanged
                      (object sender, EventArgs e)
{
  if (ddlCountry.SelectedValue == "0")
  {
    ddlCity.Items.Clear();
    ddlCity.BindDataSource(null, "Select");
  }
  else
  {
    var city = (from c in "collection or list" select new
               { Id = c.Id, Name = c.Name }).ToList();
    ddlCity.BindDataSource(city, "Select");
  }
} 

how to remove html tags and xml tags in sql server 2008 ( Best way to strip html tags from a string in sql server )

Function:
create function dbo.StripHTML(@text varchar(max))
returns varchar(max) 
as
begin
    declare @textXML xml
    declare @result varchar(max)

    set @textXML = @text;

    with doc(contents) as

    (
        select chunks.chunk.query('.') from  
         @textXML.nodes('/') as chunks(chunk)
    )
    select @result = contents.value('.', 'varchar(max)') from doc

    return @resultend
go
 

select dbo.StripHTML('This <i>is</i> an <b>html</b> test')
 
Output :
 This is an html test



How to remove html and xml tags

DECLARE @htmlXmlTags VARCHAR(1000);

SET @htmlXmlTags='<?xml version="1.0" encoding="utf-16"?><HTML><BODY>
<P STYLE="font-size:16;font-family:Calibri;
color:#000000;font-weight:normal;font-style:normal;
text-align:Left;"><SPAN>
This <i>is</i> an <b>html</b> test</SPAN>
</P></BODY></HTML>'; 

 SELECT dbo.StripHTML(Replace(@htmlXmlTags,'
<?xml version="1.0" encoding="utf-16"?>' , ''));


Output :
 This is an html test


Contact: thulasiram.eee@gmail.com