Thursday, May 26, 2011

how to set datasource for dropdownlist inside of the grid in asp.net

<asp:TemplateField>

<HeaderTemplate>

Client

</HeaderTemplate>

<ItemTemplate>

<asp:Panel ID="pnlClient" runat="server">

<asp:DropDownList ID="ddlClient" runat="server" DataTextField="Clientname" DataValueField="clientid"

DataSource='<%#GetDSfDDL(Eval("client"))%>' AutoPostBack="True" OnSelectedIndexChanged="ddlClient_SelectedIndexChanged">

</asp:DropDownList>

</asp:Panel>

<%-- <asp:Label ID="lblClient" runat="server" Text='<%# bind("Client")%>'></asp:Label>--%>

</ItemTemplate>

<EditItemTemplate>

</EditItemTemplate>

</asp:TemplateField>








public List<clientddl> GetDSfDDL(object client)

{


List<clientddl> values = new List<clientddl>();

string[] cl = client.ToString().Split('/');

 


dt = new DataTable();

dt = bussclass.fnclientlist();


for (int i = 0; i < dt.Rows.Count; i++)

{


clientddl value = new clientddl();

value.Clientid = getint(dt.Rows[i]["client_id"]);

value.Clientname = dt.Rows[i]["client_name"].ToString();

values.Add(value);


}


for (int i = 0; i < values.Count; i++)

{


clientddl temp = new clientddl();

if (values[i].Clientid == getint(cl[0]))

{


if (i > 0)

{


temp = values[0];


values[0] = values[i];


values[i] = temp;


}


}


}


 


return values;

}














Wednesday, May 25, 2011

How to play audio file in asp.net c#

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Media;
using WMPLib; //Add this COM Component Reference to your project

public partial class PlayMusic : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{

}

protected void btnPlayMusic_Click(object sender, EventArgs e)
{
string _path = "File Path";

//Method 1 using sound player class
SoundPlayer _sm = new SoundPlayer(_path);
_sm.Play();
//Method 2
Microsoft.VisualBasic.Devices.Audio _mvda = new Microsoft.VisualBasic.Devices.Audio();
_mvda.Play(_path, Microsoft.VisualBasic.AudioPlayMode.Background);


//Method 3 using WindowsMediaPlayer Class
WindowsMediaPlayerClass _wmpc = new WindowsMediaPlayerClass();
_wmpc.openPlayer(_path);
_wmpc.play();


}
}

Monday, May 9, 2011

how to copy files to local to server path using c#

string path="C:\\Users\\prag\\Desktop\\bosco\\test.txt";
string sourceFile = path;
string destinationFile = Server.MapPath("./file/test.txt");
System.IO.File.Copy(sourceFile, destinationFile);

Thursday, May 5, 2011

How to set hyperlink from the code behind using java script:

java script:


Hyperlink in grid row template:



Code Behind:


public string GetScript(object cid)
{
return "javascript:launchDetailsPage(" + cid.ToString() + ")";
}

Wednesday, May 4, 2011

how to create expandable text box in asp.net

<script language="javascript" type="text/javascript">



function setHeight(txtdesc) {


txtdesc.style.height = txtdesc.scrollHeight + "px";


 }



</script>


Design:

<asp:TextBox ID="txtNotes" runat="server" TextMode="MultiLine" Height="70px" Width="230px" onkeyup="setHeight(this)"></asp:TextBox>