Get value of checked item in CheckedListBox

by Kareem Allam 18. September 2011 18:31

 after bind CheckedListBox with data you can get value of checked items


For i As Integer = 0 To CheckedListBox1.CheckedItems.Count - 1
                    Dim XDRV As DataRowView = CType(CheckedListBox1.CheckedItems(i), DataRowView)
                    Dim XDR As DataRow = XDRV.Row
                    Dim XDisplayMember As String = XDR(CheckedListBox1.DisplayMember).ToString()
                    Dim XValueMember As String = XDR(CheckedListBox1.ValueMember).ToString()
                    MsgBox("DisplayMember : " & XDisplayMember & "   - ValueMember : " & XValueMember )
Next

 now you can use the value or Display of checked items in CheckedListBox from the 2 variables XDisplayMemberXValueMember in the loop

 

hope to be useful ,,, 


If you enjoyed this post, make sure you subscribe to my RSS feed!

How To Embed Any Media Player in GridView Control

by Kareem Allam 3. August 2011 06:01

This example shows how to use any media player in  GridView Control and Get movie file  path  (server Pathe or obtain videos from YouTube )  from MS SQL Database

 

MS SQL Database Table Structure

 

 

MS SQL Database Table Data

 

 

HTML Side

In your Page you Must insert in   GridView Control and SQL DataSource

 

<asp:SqlDataSource 
    ID="SqlDataSource1"
    runat="server"
    ConnectionString="<%$ ConnectionStrings:XConStr %>"
    SelectCommand="SELECT ID, Name, FilePath, Youtube FROM media">
</asp:SqlDataSource>

 

 

<asp:GridView
	ID="GridView1"
	runat="server"
	AutoGenerateColumns="False"
	DataKeyNames="ID"
	DataSourceID="SqlDataSource1" >

   <Columns>
 
     <asp:BoundField
	DataField="ID"
	HeaderText="ID"
	ReadOnly="True"
	SortExpression="ID" />
 
     <asp:BoundField
	DataField="Name"
	HeaderText="Name"
	SortExpression="Name" />
 
     <asp:BoundField
	DataField="FilePath"
	HeaderText="FilePath"
	SortExpression="FilePath" />
 
     <asp:CheckBoxField
	DataField="Youtube"
	HeaderText="Youtube"
	SortExpression="Youtube" />
 
  </Columns>
</asp:GridView>

 

 

THat Is the simply basic design for controls

NOW , I waill start to insert the Players

1 – Convert FilePath Field in GridView To Template Field

 

2 – Insert 2 Invisible Panels to template filed

       ( 1 For Media Palyer & The second for Youtube )

 

<asp:TemplateField HeaderText="FilePath" SortExpression="FilePath">
    <ItemTemplate>
        <asp:Panel ID="Panel_MediaPlayer" runat="server" Visible="false">
             <object width="200" height="200"
                  classid="CLSID:22d6f312-b0f6-11d0-94ab-0080c74c7e95"
                  id="MPPlayer">
             <param name="Filename" value='<%# Eval("Name") %>'>
             <param name="AutoStart" value="False">
             <param name="ShowControls" value="True">
             <param name="ShowStatusBar" value="True">
             <param name="ShowDisplay" value="False">
             <param name="AutoRewind" value="True">
                  <embed
                      type="application/x-mplayer2"
                      pluginspage="http://www.microsoft.com/Windows/Downloads/Contents/MediaPlayer/"
                      width="200" height="200" src='<%# Eval("FilePath") %>'
                      filename='<%# Eval("Name") %>' autostart="False"
                      showcontrols="True" showstatusbar="False"
                      showdisplay="False" autorewind="True">
                  </embed>
             </object>
        </asp:Panel>
                              

        <asp:Panel ID="Panel_Youtube" runat="server" Visible="false">
             <object width="200" height="200" >
             <param name='<%# Eval("Name") %>' value='<%# Eval("FilePath") %>' />
             <param name="allowFullScreen" value="true"/>
             <param name="allowscriptaccess" value="always"/>
                  <embed src='<%# Eval("FilePath") %>'
                      type="application/x-shockwave-flash"
                      allowscriptaccess="always"
                      allowfullscreen="true"
                      width="200" height="200"
                      pluginspage="http://www.adobe.com/go/getflashplayer">
                  </embed>
             </object>
        </asp:Panel>
                                
   </ItemTemplate>
</asp:TemplateField>

 


 

Code Side

 

Protected Sub GridView1_RowDataBound _
       (ByVal sender As Object, _
        ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) _
        Handles GridView1.RowDataBound
 
        Dim XPanel_MediaPlayer As New Panel
        Dim XCPanel_Youtube As New Panel
 
        If e.Row.RowType = DataControlRowType.DataRow Then
            XPanel_MediaPlayer = e.Row.FindControl("Panel_MediaPlayer")
            XCPanel_Youtube = e.Row.FindControl("Panel_Youtube")
 
            XPanel_MediaPlayer.Visible = False
            XCPanel_Youtube.Visible = False
 
            If Val(Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "Youtube"))) = 1 Then
                XCPanel_Youtube.Visible = True
            Else
                XPanel_MediaPlayer.Visible = True
            End If
 
        End If
 
    End Sub

 

 

 

 PS

You can Use any player , just insert the appropriate Object

 

Player 

File Formats 

Flash 

flv, mp3, swf

Windows Media Player 

asx, asf, avi, wma, wmv

QuickTime 

aif,aiff,aac,au,bmp,gsm,mov,mid,

midi,mpg,mpeg,mp4,m4a,psd,qt,qtif,

qif,qti,snd,tif,tiff,wav,3g2,3pg

Real Player 

ra, ram, rm, rpm, rv, smi, smil

 

 

 

Audio File

<object codebase="http://www.apple.com/qtactivex/qtplugin.cab" 
        classid="clsid:6BF52A52-394A-11d3-B153-00C04F79FAA6" 
        type="application/x-oleobject"> 
        <param name="url" value=" FileName.avi"> 
        <embed src="FileName.avi" 
            type="application/x-mplayer2" 
            pluginspage="http://www.microsoft.com/Windows/MediaPlayer/">
         </embed> 
</object>


 

 

QuickTime Movie

 

<object codebase="http://www.apple.com/qtactivex/qtplugin.cab" 
        classid="clsid:02BF25D5-8C17-4B23-BC80-D3488ABDDC6B"> 
        <param name="src" value=" FileName.mov"> 
        <embed src=" FileName.mov" 
            pluginspage="http://www.apple.com/quicktime/download/">
        </embed> 
</object>

 


Flash  Movie

<object codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7" 
        classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" 
        type="application/x-oleobject"> 
        <param name="src" value=" FileName.swf"> 
        <embed src=" FileName.swf" 
            type="application/x-shockwave-flash" 
            pluginspage="http://www.adobe.com/go/getflashplayer">
         </embed> 
</object>


If you enjoyed this post, make sure you subscribe to my RSS feed!

How to send an email in asp.net 2.0

by Kareem Allam 27. July 2011 18:12

 

Use this in web.config 

 

<system.net>
     <mailSettings>
       <smtp>
         <network 
		host="mail.domain.com" 
		port="25"  
		userName="mail@domain.com" 
		password="password"
           />     
       </smtp>
     </mailSettings>
 </system.net>

 

 

 

 Then Use this Function (VB)

 

Imports System.Net.Mail

Public Function SendMail(ByVal ToMailAddress As String, _
        ByVal FromMailAddress As String, _
        ByVal Subject As String, _
        ByVal Body As String, _
        ByVal IsHTML As Boolean) As Boolean
 
        Try
 
            Dim objMsg As New MailMessage(FromMailAddress, ToMailAddress)
 
            objMsg.IsBodyHtml = True
            objMsg.Body = Body
            objMsg.Subject = Subject
            Dim smtp As New SmtpClient
            smtp.Send(objMsg)
            SendMail = True
 
        Catch
            SendMail = False
        End Try
    End Function 


 

 

P.S.

This mail will  be sent in HTML format. The ASP's controls that I am using  are some text boxes and button send and validation controls for the required fields.

If you enjoyed this post, make sure you subscribe to my RSS feed!

About EgDev.com

If you would like to find value services with excellent quality and cost effectiveness and with a focus on speed , Just Follow

 Egypt Development Freelance Team.

Month List

Page List