How do i rewrite a code behind and add it to already jquery modal popup code

Last Reply 4 days ago By Indresh

Posted 6 days ago

I have this code on jquery that popups up on modal when user clicks on button inside datalist, now i want to add a button select inside modal, the button will be displayed based on the userstatus condition in query select. Below is the already Jquery code popup in modal Already pop jquery popup here

 

<script type="text/javascript">
         $(function () {
             $('[id*=btncall]').on('click', function () {
                 var id = $(this).closest('span').find('[id*=lblGallaryId]').html();
                 $.ajax({
                     type: "POST",
                     url: "Timeline.aspx/GetGallery",
                     data: '{id:"' + id + '"}',
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: function (response) {
                         
                         $(".userprofilepgoto").attr('src', 'PROFILEPHOTOS/' + response.d[0].Image1photo);
                         $(".namepro").html(response.d[0].Namepro);
                         $(".username").html(response.d[0].UserName);
                         $(".summary").html(response.d[0].Summary);
                       //  $(".userverifystatus").html(response.d[0].UserVerifyStatus);
                         if (response.d[0].UserVerifyStatus == "1") {
                             $('[id*=UserVerifyStatus]').show();
                         }
                         else {
                             $('[id*=UserVerifyStatus]').hide();
                         }

                         $('#myModalprofilepopup').modal('show');
                     },
                     failure: function (response) {
                         alert(response.d);
                     },
                     error: function (response) {
                         alert(response.d);
                     }
                 });
                 return false;
             });
         });


</script>

MOAL POPUP BELOW -----------------------------------------------

 

<div class="modal fade" id="myModalprofilepopup" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
                        aria-hidden="true">
                        <div class="modal-dialog">
                            <div class="modal-content" style="height:auto">
                               
                                
                                                
                                         
                                      <div  class=" " style=" position: absolute; bottom: 60px; top:129px;  left:9px; ">

         <div class=" pull-left " style="margin-bottom:6px;   background-color:transparent">
            
    
     </div>
                                 
                        </div>
                                  <a class=" pull-left"   style=" margin-left:103px; margin-top:2px">
                                    
                     <asp:Label ID="Namepro" runat="server" Text='<%# Eval("Name") %>' Font-Bold="True" CssClass="namepro"   Font-Size="Larger" ForeColor="Black" /> 
                                      <asp:Label ID="UserVerifyStatus" runat="server" CssClass="userverifystatus glyphicon glyphicon-link"
    title="." data-toggle="tooltip" Font-Size="Small" Style="display: none" ForeColor="" ></asp:Label><asp:Label ID="UserName" Text='<%#Eval("UserName") %>'  runat="server"  CssClass="username" /> 
                                       
                                         </a>
                                  <div class="pull-right" style="margin-right:8px;margin-top:8px">
                                           <asp:LinkButton ID="btnselect" runat="server" CssClass="btn btn-info">Select</asp:LinkButton>
                                    </div>
                               <asp:Label ID="lblGallaryId" Text='<%#Eval("UserId") %>'  runat="server" Font-Size="0px" /> 
                    <div class="clearfix" style=""></div>
                              
                                <div id="modalbody5"  class="modal-body">
                                
                                  
                                    <div class="clearfix" style=""></div>
                                 
                                    <asp:Label ID="Summary" runat="server" Text=" find the following file structure and contents, logically grouping  . " CssClass="summary"   Font-Size="Larger" ForeColor="Black" /> 
                                    <div class="clearfix" style=""></div>
                                        
                                          
                                             <div class="clearfix" style=""></div>
                                        
                                          
                                            
                                   </div>



                            </div></div></div>


---------------------------------------------------

Now i want to add the below btnselect to above modal then use the code behind condiction below to either display the button or hide it

 

<asp:FormView ID="CHOICE" runat="server" Width="100%" OnDataBound="CHOICE_DataBound" OnItemDataBound="CHOICE_ItemDataBound" >
        
        <ItemTemplate>
          
                      
                
                     <asp:Label ID="lblId" Text='<%#Eval("UserName") %>' Visible="false" runat="server" />
    
                     <asp:Label ID="lblUserName" Text='<%# Eval("UserName") %>' runat="server"  Visible="false"/>
                    
                     <asp:Label ID="lblUserStatus" Visible="false" runat="server" />
                                                <asp:Label ID="lblcount" Visible="false" runat="server" />
                                                <asp:Label ID="lblstatus" Visible="false" runat="server" />
                    <asp:Label ID="UserName" Text="0" Visible="false" runat="server" />
                    <div class="" style="margin-bottom:6px; margin-top:6px">

                   
                    <asp:LinkButton ID="btnselect" Text="select"  runat="server" Visible="false"

                                                         Font-Size="Larger" Width="" OnClick="selectITM" Font-Bold="True" CssClass="btn  btn-default btn-info " ForeColor="White">
                        
                                                    </asp:LinkButton>

            
 </div>
                </ItemTemplate>

    </asp:FormView>

--------------------------------- CODE BEHIND ON BUTTON SELECT

 

protected void selectITM(object sender, EventArgs e)
    {
        FormView item = (sender as LinkButton).NamingContainer as FormView;

        string usernameFk = ((item.FindControl("lblId") as Label).Text);


        using (SqlConnection con = new SqlConnection(constring))
        {
            if ((item.FindControl("btnselect") as LinkButton).Text.ToUpper() == "select")


                using (SqlCommand cmd = new SqlCommand("INSERT INTO SelectedStatus values(@UserName,@UserStatus,@Count)", con))
                {
                    
                    cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
                   
                    cmd.Parameters.AddWithValue("@UserStatus", "TRUE");
                    cmd.Parameters.AddWithValue("@Count", 1);
                    
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            else
            {
                using (SqlCommand cmd = new SqlCommand("DELETE FROM SelectedStatus WHERE [email protected]", con))
                {
                    // cmd.Parameters.AddWithValue("@FavoriteId", favoriteId);
                    cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
                    con.Open();
                    cmd.ExecuteNonQuery();
                    con.Close();
                }
            }
        }
        GetData();



    }

    protected void CHOICE_DataBound(object sender, EventArgs e)
    {
        using (SqlConnection con = new SqlConnection(constring))
        {
            using (SqlCommand cmd = new SqlCommand("SELECT * FROM SelectedStatus where  UserName='" + Session["userName"] + "' ", con))
            {
                con.Open();
                //cmd.Parameters.AddWithValue("@UserName", Session["userName"]);
                SqlDataReader idr = cmd.ExecuteReader();
                if (idr.Read())
                {
                    (CHOICE.FindControl("btnselect") as LinkButton).Text = "SELECTED";
                    (CHOICE.FindControl("lblId") as Label).Text = idr["UserName"].ToString();

                }
                con.Close();
            }


 

You are viewing reply posted by: Indresh 6 days ago.
Posted 6 days ago Modified on 4 days ago

Hi micah,

I have modified the code. So please refer the below code and you need to implement as per your requirement.

JavaScript

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
    $(function () {
        $('[id*=btncall]').on('click', function () {
            var id = $(this).closest('span').find('[id*=lblGallaryId1]').html();
            GetStatus(id);
            $.ajax({
                type: "POST",
                url: "Timeline.aspx/GetGallery",
                data: '{id:"' + id + '"}',
                contentType: "application/json; charset=utf-8",
                dataType: "json",
                success: function (response) {
                    $(".userprofilepgoto").attr('src', 'PROFILEPHOTOS/' + response.d[0].Image1photo);
                    $(".namepro").html(response.d[0].Namepro);
                    $(".username").html(response.d[0].UserName);
                    $(".summary").html(response.d[0].Summary);
                    if (response.d[0].UserVerifyStatus == "1") {
                        $('[id*=UserVerifyStatus]').show();
                        $('[id*=btnselect]').show();
                    }
                    else {
                        $('[id*=UserVerifyStatus]').hide();
                        $('[id*=btnselect]').hide();
                    }

                    $('#myModalprofilepopup').modal('show');
                },
                failure: function (response) {
                    alert(response.d);
                },
                error: function (response) {
                    alert(response.d);
                }
            });
            return false;
        });
    });
    function GetStatus(GallaryId) {
        var id = GallaryId;
        $.ajax({
            type: "POST",
            url: "Timeline.aspx/GetSTATUS",
            data: '{id:"' + id + '"}',
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            success: function (response) {
           // Populate data here.You need to change data assign as per your requirement.
                $('[id*=lblId]').text(response.d[0].UserName);
                $('[id*=btnStatus]').text(response.d[0].btnStatus);
                $('#myModalprofilepopup').modal('show');
            },
            failure: function (response) {
                alert(response.d);
            },
            error: function (response) {
                alert(response.d);
            }
        });
    }
</script>

C#

[WebMethod]
public static List<Gallery> GetGallery(int id)
{
    string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT ImageBanner,ImageName,UserName,Name,UserStatus FROM User3 WHERE UserId = '" + id + "'"))
        {
            cmd.Connection = con;
            List<Gallery> gallery = new List<Gallery>();
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                gallery.Add(new Gallery
                {
                    photos = sdr["ImageBanner"].ToString(),
                    Image1photo = sdr["ImageName"].ToString(),
                    UserName = sdr["UserName"].ToString(),
                    Namepro = sdr["Name"].ToString(),
                    UserStatus = sdr["UserStatus"].ToString(),
                });
            }

            con.Close();
            return gallery;
        }
    }
}

[WebMethod]
public static List<STATUS> GetSTATUS(int id)
{
    string constr = ConfigurationManager.ConnectionStrings["DB"].ConnectionString;
    using (SqlConnection con = new SqlConnection(constr))
    {
        using (SqlCommand cmd = new SqlCommand("SELECT * FROM FStatus where fUserName='" + HttpContext.Current.Session["userName"] + "'  AND UserName='" + HttpContext.Current.Session["userName"] + "' ", con))
        {
            cmd.Connection = con;
            List<STATUS> status = new List<STATUS>();
            con.Open();
            SqlDataReader sdr = cmd.ExecuteReader();
            while (sdr.Read())
            {
                status.Add(new STATUS
                {
                    UserName = sdr["UserName"].ToString(),
                    btnStatus = "Selected"
                });
            }

            return status;
        }
    }
}

public class STATUS
{
    public string UserName { get; set; }
    public string btnStatus { get; set; }
}

public class Gallery
{
    public string photos { get; set; }
    public string Image1photo { get; set; }
    public string UserName { get; set; }
    public string Namepro { get; set; }
    public string UserStatus { get; set; }
}

Vb.Net

<WebMethod> _
Public Shared Function GetGallery(id As Integer) As List(Of Gallery)
	Dim constr As String = ConfigurationManager.ConnectionStrings("DB").ConnectionString
	Using con As New SqlConnection(constr)
		Using cmd As New SqlCommand("SELECT ImageBanner,ImageName,UserName,Name,UserStatus FROM User3 WHERE UserId = '" + id + "'")
			cmd.Connection = con
			Dim gallery As New List(Of Gallery)()
			con.Open()
			Dim sdr As SqlDataReader = cmd.ExecuteReader()
			While sdr.Read()
				gallery.Add(New Gallery() With { _
					Key .photos = sdr("ImageBanner").ToString(), _
					Key .Image1photo = sdr("ImageName").ToString(), _
					Key .UserName = sdr("UserName").ToString(), _
					Key .Namepro = sdr("Name").ToString(), _
					Key .UserStatus = sdr("UserStatus").ToString() _
				})
			End While

			con.Close()
			Return gallery
		End Using
	End Using
End Function

<WebMethod> _
Public Shared Function GetSTATUS(id As Integer) As List(Of STATUS)
	Dim constr As String = ConfigurationManager.ConnectionStrings("DB").ConnectionString
	Using con As New SqlConnection(constr)
		Using cmd As New SqlCommand("SELECT * FROM FStatus where fUserName='" + HttpContext.Current.Session("userName") + "'  AND UserName='" + HttpContext.Current.Session("userName") + "' ", con)
			cmd.Connection = con
			Dim status As New List(Of STATUS)()
			con.Open()
			Dim sdr As SqlDataReader = cmd.ExecuteReader()
			While sdr.Read()
				status.Add(New STATUS() With { _
					Key .UserName = sdr("UserName").ToString(), _
					Key .btnStatus = "Selected" _
				})
			End While

			Return status
		End Using
	End Using
End Function

Public Class STATUS
	Public Property UserName() As String
		Get
			Return m_UserName
		End Get
		Set
			m_UserName = Value
		End Set
	End Property
	Private m_UserName As String
	Public Property btnStatus() As String
		Get
			Return m_btnStatus
		End Get
		Set
			m_btnStatus = Value
		End Set
	End Property
	Private m_btnStatus As String
End Class

Public Class Gallery
	Public Property photos() As String
		Get
			Return m_photos
		End Get
		Set
			m_photos = Value
		End Set
	End Property
	Private m_photos As String
	Public Property Image1photo() As String
		Get
			Return m_Image1photo
		End Get
		Set
			m_Image1photo = Value
		End Set
	End Property
	Private m_Image1photo As String
	Public Property UserName() As String
		Get
			Return m_UserName
		End Get
		Set
			m_UserName = Value
		End Set
	End Property
	Private m_UserName As String
	Public Property Namepro() As String
		Get
			Return m_Namepro
		End Get
		Set
			m_Namepro = Value
		End Set
	End Property
	Private m_Namepro As String
	Public Property UserStatus() As String
		Get
			Return m_UserStatus
		End Get
		Set
			m_UserStatus = Value
		End Set
	End Property
	Private m_UserStatus As String
End Class

 

 

I agree, here is the link: https://www.e-iceblue.com/Introduce/spire-office-for-net-free.html?aff_id=108