Tag Archives: Literal

[RESOLVED]How do I feed a variable to a function for a user to select show or fadeIn or slideDown to use such functions?

I want to feed a variable through to a function that will either:

div1.show("slow");

or

div1.fadeIn("slow");

or

div1.slideDown("slow")

for example, I would like to have a user do this:

divShow(‘fadeIn’);, or divShow(‘slideDown’);, or divShow(‘show’);

how do I do that?

use javascript’s literal method name approach rather than the dot notation:

   var methodName = "show";
   div1[methodName]("slow");

Hi JAYHAWKER,

Thanks for your post.

As for your problem, you could try the following sample.

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style>
        #div1 {
            width: 100px;
            height: 100px;
            background-color: #0094ff;
        }
    </style>
    <script src="../../Scripts/jquery-1.8.2.js"></script>
    <script>
        $(function () {
            $("#div1").hide();

            $("#btnshow").click(function () {
                var str = $(":checked").attr("value");
                //alert(str);
                if (str == "Show") {
                    $("#div1").show("slow");
                }
                else if (str == "FadeIn") {
                    $("#div1").fadeIn("slow");
                }
                else if (str == "SlideDown") {
                    $("#div1").slideDown("slow");
                }
                else if (str == "Hide") {
                    $("#div1").hide();
                }
            })
        })
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div>
            <asp:RadioButton ID="rdb1" runat="server" GroupName="show" Checked="true" Text="Show" value="Show" />
            <asp:RadioButton ID="rdb2" runat="server" GroupName="show" Text="FadeIn" value="FadeIn" />
            <asp:RadioButton ID="rdb3" runat="server" GroupName="show" Text="SlideDown" value="SlideDown" />
            <asp:RadioButton ID="rdb4" runat="server" GroupName="show" Text="Hide" value="Hide" />
            <input id="btnshow" type="button" value="Show" />
            <br />
            <div id="div1"></div>
        </div>
    </form>
</body>
</html>

If you have any question about this issue, please post back freely.

Best Regards,

Fei Han

[RESOLVED]How can I inject this letters?

Hello,

When i trying to inject JavaScript getting "Unrecognized Excape Sequence" Error. (Which letters in Bold)

How can should change this letters?

i.substr(j).replace(/(d{3})(?=d)/g, ‘$1′ + thousand)

Thank You!

Hm, it looks correct and works for me, see example http://jsbin.com/feqibudaya/1/ 

In case you want to have a thousand separator, see second function 

num.toString().replace(/(d)(?=(d{3})+(?!d))/g, "$1,"); 

More info: http://blog.tompawlak.org/number-currency-formatting-javascript 

omerdemir

i.substr(j).replace(/(d{3})(?=d)/g, ‘$1′ + thousand)

Try to add one more and make it a double \ so that it will mean  literal in the Reg exp  string, and not as a escape sequence.

i.substr(j).replace(/(\d{3})(?=\d)/g, '$1' + thousand)

[RESOLVED]Keeping an option list within a Repeater Open inspite intital CSS.

I have a Repeater with CSS designed to Open/Close upon clicking on the ‘+’/’-’ (see below):

--- CSS ---
sliding-box .box-content{
	width:646px;
	margin:7px 0 0;
	padding:16px 20px 18px;
	background:#fff;
}
.sliding-box .box-content:after{
	content:"";
	display:block;
	clear:both;
}

--- HTML ---
<div class="box-content" style="display: none;">
    <ul class="list-options">
        <asp:Repeater ID="ProductOptions" runat="server" OnItemDataBound="ProductOptions_ItemDataBound">
            <ItemTemplate>
                <li>
                    <asp:CheckBox runat="server" ID="OptionCheckbox" CssClass="checkbox" OnCheckedChanged="OptionCheckbox_CheckedChanged" AutoPostBack="true" />
                </li>
            </ItemTemplate>
        </asp:Repeater>
    </ul>
</div>

--- Page Renders as per below --------
// 1. Upon initial Page Load
+ Options

// 2. When clicking on the '+', checkboxes are displayed
- Options
   Checkbox 1
   Checkbox 2
   Checkbox 3

When Selecting a Checkbox, a Postback occurs which collapses the Options List.

Can someone show me how to keep this Option List object Open after selecting the Checkbox?

Hi baruchb,

Thanks for your post.

As for your problem, I’d like to know how do you open the Option List when you click the ‘+’. Could you show us more relevant code? It will help us to reproduce your problem.

Best Regards,

Fei Han

Sure! Below is the full HTML for this section followed by the CSS for the SlidingBox. I am not an expert on CSS so I am not sure if/how to ‘doctor’ the CSS to make this happen. Bottom line is that: I need the sliding box to be closed for ALL page loads except
when PostBack from a Checkbox within the repeater (which I am able to detect at Page_Load by interrogating the Request.Params["_EVENTTARGET"].

HTML
----
<asp:Panel ID="ProductOptionsPanel" runat="server">
    <!-- product options -->
    <div class="sliding-box">
        <div class="sliding-box-holder">
            <div class="title">
                <a href="#" class="open-close">
                    <asp:Literal ID="OptionsTitle" runat="server" />
                    - Options</a>
            </div>
            <div class="box-content">
                <ul class="list-options">
                    <asp:Repeater ID="ProductOptions" runat="server" OnItemDataBound="ProductOptions_ItemDataBound">
                        <ItemTemplate>
                            <li>
                                <asp:CheckBox runat="server" ID="OptionCheckbox" CssClass="checkbox" OnCheckedChanged="OptionCheckbox_CheckedChanged" AutoPostBack="true" />
                                <div class="holder">
                                    <asp:Literal ID="Description" runat="server" />
                                    <asp:HiddenField ID="Code" runat="server" />
                                    <asp:HiddenField ID="SalesItemNumber" runat="server" />
                                </div>
                            </li>
                        </ItemTemplate>
                    </asp:Repeater>
                </ul>
            </div>
        </div>
    </div>

<!--child options -->
<asp:panel id="ChildOptionsPanel" CSSClass="sliding-box" runat="Server">
.
.
.
CSS
---
/* sliding-box */
.sliding-box{
	width:100%;
	position:relative;
	z-index:5;
	padding:0 0 10px;
	color:#242424;
}
.sliding-box-holder{
	height:1%;
	padding:7px;
	background:#e9eaec;
}
.sliding-box-holder:after{
	content:"";
	display:block;
	clear:both;
}
.sliding-box .title{
	width:100%;
	overflow:hidden;
}
.sliding-box .open-close{
	height:1%;
	overflow:hidden;
	display:block;
	padding:0 36px;
	font-size:16px;
	line-height:38px;
	color:#242424;
	background: url(images/bg-sliding-box-close.gif) no-repeat 5px 50%;
}
.active .open-close{background: url(images/bg-sliding-box-open.gif) no-repeat 5px 50%;}
.sliding-box .open-close:hover{
	color:#c6178d;
	text-decoration:none;
}
.sliding-box .open-close img{
	float:left;
	margin:0 10px 0 0;
}
.sliding-box .box-content{
	width:646px;
	margin:7px 0 0;
	padding:16px 20px 18px;
	background:#fff;
}
.sliding-box .box-content:after{
	content:"";
	display:block;
	clear:both;
}
.sliding-box .item-table .col-1{width:46%;}
.sliding-box .item-table .col-2{width:26%;}
.sliding-box .item-table .col-3{width:20%;}
.sliding-box .item-table .col-4{padding-right:10px;}
.sliding-box p{margin:0 0 21px;}
/* item-table2 */
.item-table2 .col-1,
.sliding-box .item-table2 .col-1{width:50%;}
.item-table2 .col-2,
.sliding-box .item-table2 .col-2{width:22%;}
.item-table2 .col-3,
.sliding-box .item-table2 .col-3{width:34%;}
.headline{
	height:1%;
	overflow:hidden;
}

You need to store the id of the open sections in a hidden field element and on postback ensure those fields are initially visible.  The following link is for remembering the selected tab between postbacks but the concept is the same, just adapt the code
as needed.

http://forums.asp.net/t/1964624.aspx?Maintaining+tab+position+on+post+back

My problem is not remembering WHAT to keep open but rather HOW. If you are versed in CSS or able to provide a solution for how to keep the SlideBox open given conditions specified in my previous thread, it will be greatly appreciated.

I posted code as per your request. Any idea yet?

Hi baruchb1,

baruchb1

My problem is not remembering WHAT to keep open but rather HOW.

Here is a Collapsible Repeater Demo, you could refer to it.

Besides, you could also refer to this article.

Hope it will be helpful to you.

Best Regards,

Fei Han

[RESOLVED]how to run a video as pop up when we click on it in asp.net website

Hi first my code

========

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="VideoDemo._Default" %>
<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="cc1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
     <title>DEMO | Embebbed YouTube object</title>

</head>
<body>
   <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" />
        <asp:UpdatePanel ID="UpdatePanel1" runat="server" updatemode="Conditional" >
            <ContentTemplate>
            <div>
                <!– ALL CONTENT IS SHOWN FOR DEMO PURPOSE ONLY–>
                <asp:DropDownList ID="cmbPlaylist" runat="server" AutoPostBack="True">
                    <asp:ListItem Value="raRaxt_KM9Q">Sound Of Silence (Masters of Chant)</asp:ListItem>
                    <asp:ListItem Value="8qSeYLhe09s">For Whom The Bell Tolls (Bee Gees)</asp:ListItem>
                </asp:DropDownList>
                <br /><br />
                <asp:Literal ID="Literal1" runat="server"></asp:Literal>
            </div>
            </ContentTemplate>
          </asp:UpdatePanel>   
        </form>

</body>
</html>

===========

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace VideoDemo
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        { Literal1.Text = GetYouTubeScript(cmbPlaylist.SelectedValue); }

        protected string GetYouTubeScript(string id)
        {
            string scr = @"<object width=’320′ height=’240′> ";
            scr = scr + @"<param name=’movie’ value=’http://www.youtube.com/v/" + id + "’></param> ";
            scr = scr + @"<param name=’allowFullScreen’ value=’true’></param> ";
            scr = scr + @"<param name=’allowscriptaccess’ value=’always’></param> ";
            scr = scr + @"<embed src=’http://www.youtube.com/v/" + id + "’ ";
            scr = scr + @"type=’application/x-shockwave-flash’ allowscriptaccess=’always’ ";
            scr = scr + @"allowfullscreen=’true’ width=’320′ height=’240′> ";
            scr = scr + @"</embed></object>";
            return scr;
        }

    }
}

This code asctually runs the video from youtube when we call it using dropdown list.But now what i was trying ot do is to run the video as pop up when anybody clicks on it but didnt successed.I trued using ModalPopupExtender but completely failed.please
help me

And another thing is like i am directly taking the video from youtube.can i download the video and keep it in personal computer and then call it in my applicationIt will be really hepful if anybody knows this

Thanks

fanu

Hello

You can consider place an iframe in the ModalPopup.

In that iframe, it has the page that runs the script to load the video.

[RESOLVED]Add Edit button command column from VB.net codebehind

I have created a series of gridviews that display budget data from a sql database.

I have populated the gridviews from the code behind as shown in the snipets.

I am wondering if it is possible to created the edit/update button or link from the code behind or does this have to be done from the aspx page. I have only been able to find documenation on how to do this from the html.

Thanks in advance. 

The HTML aspx page…

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Budget.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <!-- Le styles -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
.table-right
      {
          text-align: right !important;
      }
    </style>
    <link href="../css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <form id="form1" runat="server" value="1">
        <p>Pick a month to update:&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" AutoPostBack="True"
            DataSourceID="SqlDataSource1" DataTextField="X" DataValueField="MY_ID">
            <asp:ListItem Selected="True" Value="0">Select Month</asp:ListItem>
          
        </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server"
            ConnectionString="<%$ ConnectionStrings:BudgetConnectionString %>"
            SelectCommand="p_DisplayMonths" SelectCommandType="StoredProcedure">
        </asp:SqlDataSource>
        </p>
            <div class="row">
            
                <div class="span4">
                   
                    <asp:Literal ID="Literal1" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView1" runat="server"  OnRowDataBound="GridView_RowDataBound" >
                    </asp:GridView>
                    <asp:GridView ID="GridView4" runat="server" >
                  
                    </asp:GridView>

                    
                </div>

                <div class="span4">
                    <asp:Literal ID="Literal2" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView_RowDataBound" >
                    </asp:GridView>
                    <asp:GridView ID="GridView5" runat="server" >
                  
                    </asp:GridView>
                </div>

                <div class="span4">
                    <asp:Literal ID="Literal3" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView3" runat="server" OnRowDataBound="GridView_RowDataBound">
                    </asp:GridView>
                    <asp:GridView ID="GridView6" runat="server" >
                  
                    </asp:GridView>
                </div>

            </div>
        </form>
    </div>
        <script src="http://code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    </body>
</html>

The codebehind page…

Imports System
Imports System.Data
Imports System.Data.SqlClient


Public Class WebForm1
    Inherits System.Web.UI.Page
    Public Property DisplayD As String
    Public Property Display As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

       
    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        'Create the action of the dropdown menu to select the desired month

        If DropDownList1.SelectedItem.Value = "0" Then
        Else
            Literal3.Text = ""
            'In the event there is no data for pay period 3 and a month is selected with pay period there this resets the literal title for PP3 to nothing
        End If
        con = GetConnect()
        con.Open()
        Dim month = DropDownList1.SelectedItem.Value()
        'Value for the month is populated here

        'The following gets the data from the database to the gridviews 


        Dim gv As GridView
        Dim tb As Literal
        For value As Integer = 1 To 6
            Dim gvd As New DataDisplay
            If value < 4 Then
                gvd.Name = "gvd" & value
                gvd.Display = "p_DisplayBills2"
                gvd.DisplayD = String.Format("p_DisplayBills2 {0}, {1}", month, value)

            End If
            If value > 3 And value < 7 Then
                Dim cal As Integer = value - 3
                gvd.Name = "gvd" & value
                gvd.Display = "p_CalulatePayPerBills"
                gvd.DisplayD = String.Format("p_CalulatePayPerBills {0}, {1}", month, cal)
            End If
            gv = FindControl("GridView" & value)
            gv.DataSource = gvd.DataDisplay()
            gv.DataBind()

            If value < 4 Then
                Dim rows1 As Integer
                Dim rows2 As Integer
                Dim rows3 As Integer
                If value = 1 Then
                    rows1 = gv.Rows.Count()
                End If
                If value = 2 Then
                    rows2 = gv.Rows.Count()
                End If
                If value = 3 Then
                    rows3 = gv.Rows.Count()
                End If
                Dim arow As Integer() = {rows1, rows2, rows3}
                Dim larrow As Integer = arow.Max()


                If gv.Rows.Count() < larrow Then
                    Dim ds1 As DataSet = gvd.DataDisplay()
                    Dim x As Integer = larrow - gv.Rows.Count()

                    For i As Integer = 1 To x

                        Dim dr = ds1.Tables(0).NewRow()
                        ds1.Tables(0).Rows.Add(dr)

                    Next
                    gv.DataSource = ds1.Tables(0)
                    gv.DataBind()

                End If
            End If

            If value < 4 Then
                For Each oItem As GridViewRow In gv.Rows
                    Dim getFirstColValue As String = oItem.Cells(0).Text
                    oItem.Attributes.Add("id", getFirstColValue)
                Next

                For Each r As GridViewRow In gv.Rows
                    r.Cells(0).Style.Add("display", "none")
                Next
            End If
            gv.Attributes.Add("class", "table table-condensed table-hover table-bordered table-striped")
            If gv.Rows.Count > 0 And value < 4 Then
                gv.HeaderRow.Cells(0).Visible = False
                gv.HeaderRow.Cells(1).Text = "Bill Name"
                gv.HeaderRow.Cells(3).Text = "Bill Pay Status"
            End If
            If value > 3 And value < 7 Then
                Dim totaltext As Integer = value - 3
                gv.HeaderRow.Cells(0).Text = String.Format("Total Pay Period {0}", totaltext)
            End If
            If value = 1 Or value = 2 Then
                tb = FindControl("Literal" & value)
                tb.Text = String.Format("<p>Pay Period: {0}</p>", value)
            End If
            If value = 3 Then
                tb = FindControl("Literal" & value)
                tb.Text = String.Format("<p>Pay Period: {0} and Credit Card Bills</p>", value)
            End If
        Next





    End Sub
    Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.DataRow Then

            e.Row.Cells(2).Attributes.Add("Class", "table-right")
            'e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>"

        End If


    End Sub
End Class

The datadisplay function/class

Imports System
Imports System.Data
Imports System.Data.SqlClient


Public Class DataDisplay
    Public Property Name As String
    Public Property DisplayD As String
    Public Property Display As String
 

    Public Function DataDisplay()
        Dim str As String = DisplayD
        Dim cmd As New SqlCommand(str, con)

        Dim Ds As New DataSet()
        Dim da As New SqlDataAdapter(cmd)

        da.Fill(Ds, Display)
        Return Ds

    End Function

End Class

Dim cf as CommandField = new CommandField()
Gv.Colums.Add(cf)

Another way,

Dim lb as LinkButton=new LinkButton
Lb.CommandName="edit"
Lb.Text="edit"
Gv.Cells(n).Controls.Add(lb)

Thank you. The second option worked with a little bit of modification…

For Each commanditem As GridViewRow In gv.Rows
    Dim lb As LinkButton = New LinkButton
    lb.CommandName = "edit"
    lb.Text = "edit"
    commanditem.Cells(0).Controls.Add(lb)
Next

Two more questions… 

1 The CF replaces the column that had the primary key from the database… How would I pass that info into the CF as say a value or ID?

I tried this… but it made the id gridview1_0_1 etc etc…

 lb.ID = commanditem.Cells(0).Text

2. When I click on the edit button it turns the column back into the primary key data from the sql data base… Is there a way to call that event and do something with it?

Thanks in advance!

I’m not sure what you mean. To set/get information from current GridView row you can use GridView RowEditing / RowUpdating event. For example :

Dim id as Integer = GridView1.DataKeys(e.NewEditIndex).Value;

Thank you that worked!

[RESOLVED]detailsview validation

I need to do a validaton for a textfield in a detailsview. I have used "custom validator" and want to fire the "server_validate" event. but the "server_validate" event does not fire. I have google for sometime and came to know that it is not possible. However
i need to understand why it is not possible??

Any ideas??[8-)]

 

who said to you that server side validation not fires ?

Check http://forums.asp.net/t/1297601.aspx 

http://forums.asp.net/t/1102008.aspx 

Where did you find that’s not possible? This is normal practice, so it should work!

kamii47

 http://forums.asp.net/t/1102008.aspx 

After seeing the following post only i posted for clarity.

I tried my self by adding a detailsview and a customvalidator and "server_valitdate" function for the custom validator. but the point is the "server_validate" function is never hit.. I would like to know why it was  not possible.??

 

Show an example of the detailsview and the server_validate function?

okay here is code

            <asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False" DataKeyNames="Id"
                DataSourceID="SqlDataSource1" Height="50px" Width="125px">
                <Fields>
                    <asp:TemplateField HeaderText="Id" InsertVisible="False" SortExpression="Id">
                        <EditItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text=’<%# Eval("Id") %>’></asp:Label>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label1" runat="server" Text=’<%# Bind("Id") %>’></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Name" SortExpression="Name">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text=’<%# Bind("Name") %>’></asp:TextBox>
                            <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBox1"
                                EnableClientScript="False" ErrorMessage="*">*</asp:RequiredFieldValidator>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label2" runat="server" Text=’<%# Bind("Name") %>’></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:TemplateField HeaderText="Position" SortExpression="Position">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox2" runat="server" Text=’<%# Bind("Position") %>’></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            <asp:Label ID="Label3" runat="server" Text=’<%# Bind("Position") %>’></asp:Label>
                        </ItemTemplate>
                    </asp:TemplateField>
                    <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" ShowInsertButton="True" />
                </Fields>
            </asp:DetailsView>

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
             SelectCommand="SELECT * FROM [MovieCategories]"
            UpdateCommand="UPDATE [MovieCategories] SET [Name] = @Name, [Position] = @Position WHERE [Id] = @Id">
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Position" Type="Int32" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>
             </asp:SqlDataSource>

code behind

 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
        {
            TextBox tb = (TextBox)DetailsView1.FindControl("TextBox1");
            if (tb.Text.Length > 0)
            {
                if (args.Value.Length < 1)
                {
                    args.IsValid = false;
                }
                else
                {
                    args.IsValid = true;
                }
            }
        }
    }

Any help???

 

Where is the customvallidator that calls the function? [8-|]

And what exactly is it that you want the validator to do?

Yes From mentioned code we can’t see the custom validator with CustomValidator1_ServerValidate function/event .Is any thing missing in your code ?

kamii47

Yes From mentioned code we can’t see the custom validator with CustomValidator1_ServerValidate function/event .Is any thing missing in your code ?

it is there in the post. but i am giving for reference

 protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
    {
        if (DetailsView1.CurrentMode == DetailsViewMode.Edit)
        {
            TextBox tb = (TextBox)DetailsView1.FindControl("TextBox1");
            if (tb.Text.Length > 0)
            {
                if (args.Value.Length < 1)
                {
                    args.IsValid = false;
                }
                else
                {
                    args.IsValid = true;
                }
            }
        }
    }

A, now I understand the problem!

You made a function, but you forgot to put the Custom Validator in the HTML Markup. Just Add:

<asp:CustomValidator ID="CustomValidator1" runat="server" ErrorMessage="ErrorMessage" OnServerValidate="CustomValidator1_ServerValidate"  />

Ganesh Jee ,

I can’t see the CustomValidator where CustomValidator1_ServerValidate is binded.

Is there any asp:CustomValidator control with above server validation function is present in your markup ?

 

kamii47

Ganesh Jee ,

I can’t see the CustomValidator where CustomValidator1_ServerValidate is binded.

Is there any asp:CustomValidator control with above server validation function is present in your markup ?

here is the code

<EditItemTemplate>

<asp:TextBox
ID="TextBox1"
runat="server"
Text=’<%# Bind("Name") %>‘></asp:TextBox>&nbsp;

<asp:CustomValidator
ID="CustomValidator1"
runat="server"
ControlToValidate="TextBox1"

ErrorMessage="CustomValidator"
OnServerValidate="CustomValidator1_ServerValidate"></asp:CustomValidator>

</EditItemTemplate>

Sorry, i might have missed out while pasting the code.

 

Are you sure this is not firing?  Do you have a breakpoint on the first line of your event handler?  Maybe the DetailsView1 is in insert mode and your code is working perfectly.

try to set the OldValuesParameterFormatString Property in the SqlDataSource:

  <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
             SelectCommand="SELECT * FROM [MovieCategories]"
             OldValuesParameterFormatString="{0}"
             UpdateCommand="UPDATE [MovieCategories] SET [Name] = @Name, [Position] = @Position WHERE [Id] = @Id">
            <UpdateParameters>
                <asp:Parameter Name="Name" Type="String" />
                <asp:Parameter Name="Position" Type="Int32" />
                <asp:Parameter Name="Id" Type="Int32" />
            </UpdateParameters>
             </asp:SqlDataSource>

 

Hi Ganesh ,

Try to add ValidateEmptyText="True"

Otherwise , it will not fire the event hanlder when the textbox is empty.

 

Samu Zhang – MSFT

Hi Ganesh ,

Try to add ValidateEmptyText="True"

Yes. it is Server side event is fireing nw.

 

We Are Glad that u have finally solved your problem.

Ganesh Jee Please mark the Post that help you in solving your problem as answer.[not your own post [:D]]

I tried this, but i want to use custom validator in insert mode but still not firing

any suggestions? will it fire inserttemplate?

Yerbol

I tried this, but i want to use custom validator in insert mode but still not firing

any suggestions? will it fire inserttemplate?

 

If you” ve a question. please start your own thread?

http://www.mikesdotnetting.com/Article/69

I was having the same issue with the CustomValidator not firing while a DetailsView was in Insert mode. Some of the responses above helped to to figure out more of what is going on.  Here is what I’ve found: the CustomValidator will only fire after all the
other validator types on the form have fired and validate successfully.

To explain what I mean consider this example:

<asp:GridView ID="gvNews" runat="server" Width="100%" DataSourceID="sqlNews" DataKeyNames="newsId" CellPadding="4" AutoGenerateColumns="false">
  <Columns>
    <asp:CommandField ButtonType="Button" SelectText="View/Edit" ShowSelectButton="true" ItemStyle-Width="75px" />
    <asp:TemplateField HeaderText="Date">
      <ItemStyle Width="160px" />
      <ItemTemplate>
        <asp:Literal ID="gvDate" runat="server" Text=’<%# Eval("newsDate", "{0:MMMM dd, yyyy @ hh:mm tt}") %>’ />
      </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Title">
      <ItemTemplate>
        <asp:Literal ID="gvTitle" runat="server" Text=’<%# Eval("Title") %>’ />
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>

<div style="margin-top: 12px;">
  <asp:DetailsView ID="dvNews" runat="server" Width="100%" DataSourceID="sqlNewsDetails" DataKeyNames="newsId" CellPadding="6" AutoGenerateRows="false">
    <FieldHeaderStyle Width="100px" />
    <Fields>
      <asp:CommandField ButtonType="Button" EditText="Edit" UpdateText="Save Changes" CancelText="Cancel" ShowEditButton="true" />
      <asp:TemplateField HeaderText="Title*">
        <ItemTemplate>
          <asp:Literal ID="dvTitle" runat="server" Text=’<%# Eval("title_EN") %>’ />
        </ItemTemplate>
        <EditItemTemplate>
          <asp:TextBox ID="txtTitle" runat="server" Width="350px" MaxLength="75" Text=’<%# Bind("title_EN") %>’ />
          <asp:RequiredFieldValidator ID="rfvTitle" runat="server" ControlToValidate="txtTitle" CssClass="errorMessage" Display="Dynamic">What is the Title?</asp:RequiredFieldValidator>
        </EditItemTemplate>
      </asp:TemplateField>
      <asp:TemplateField HeaderText="Video">
        <ItemTemplate>
          <asp:Literal ID="dvVideo" runat="server" Text=’<%# If(String.IsNullOrEmpty(Eval("videoId").ToString), "", String.Format("({0}) {1}", Eval("streamingProviderName"), Eval("videoId"))) %>’ />
        </ItemTemplate>
        <EditItemTemplate>
          <div>
            <asp:DropDownList ID="ddlVideoProvider" runat="server" Width="355px" DataSourceID="sqlVideoProviders" DataTextField="streamingProviderName" DataValueField="providerId" SelectedValue=’<%# Bind("videoProviderId") %>’ AppendDataBoundItems="true">
              <asp:ListItem Text="Select a Streaming Video Provider from the list…" Value="" />
            </asp:DropDownList>
            <asp:CustomValidator ID="cvVideoProvider" runat="server" ControlToValidate="ddlVideoProvider" OnServerValidate="validateVideoProvider" ValidateEmptyText="true" CssClass="errorMessage" Display="Dynamic">If you select a Video Provider, you must enter
a Video ID.</asp:CustomValidator>
          </div>
          <div>
            <asp:TextBox ID="txtVideoId" runat="server" Width="350px" MaxLength="25" Text=’<%# Bind("videoId") %>’ />
            <asp:CustomValidator ID="cvVideoId" runat="server" ControlToValidate="txtVideoId" OnServerValidate="validateVideoId" ValidateEmptyText="true" CssClass="errorMessage" Display="Dynamic">If you enter a Video Id, you must select a Video Provider.</asp:CustomValidator>
          </div>
        </EditItemTemplate>
      </asp:TemplateField>
    </Fields>
  </asp:DetailsView>
</div>

<asp:SqlDataSource ID="sqlNews" runat="server" ConnectionString="<%$ ConnectionStrings: ConnString %>"

SelectCommand="SELECT newsId, Title_EN AS Title, newsDate FROM cms_News ORDER BY newsDate DESC" SelectCommandType="Text">
</asp:SqlDataSource>

<asp:SqlDataSource ID="sqlNewsDetails" runat="server" ConnectionString="<%$ ConnectionStrings: ConnString %>"

SelectCommand="SELECT newsId, title_EN, videoId, videoProviderId, streamingProviderName FROM cms_News n LEFT JOIN cms_VideoProviders vp ON n.videoProviderId=vp.providerId WHERE newsId=@newsId" SelectCommandType="Text"
UpdateCommand="UPDATE cms_News SET title_EN=@title_EN, videoId=@videoId, videoProviderId=@videoProviderId WHERE newsId=@newsId" UpdateCommandType="Text">
<SelectParameters>
  <asp:ControlParameter Name="newsId" Type="Int32" ControlID="gvNews" PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

<asp:SqlDataSource ID="sqlVideoProviders" runat="server" ConnectionString="<%$ ConnectionStrings: ConnString %>"
SelectCommand="SELECT providerId, streamingProviderName FROM cms_VideoProviders ORDER BY streamingProviderName" SelectCommandType="Text">
</asp:SqlDataSource>

This is a fully functioning demo. All you need to do is create a database with the two tables showing in the SqlDataSource statements. The idea is the GridView shows all of the news items. Each news item can have an embedded video associated with it. In
order to provide flexibility on the embedded videos, the VideoProvider table defines all the available video providers. The CustomValidators make sure that if a Video Provider is selected then a VideoId is entered and visa versa.

Notice how the Title field is marked as a required field and has a RequiredFieldValidator attached to it. If the Title field has an entry in it (and therefore the RequiredFieldValidator is successful) then, and only then will the CustomValidators fire and
make sure the the Video stuff is all there if an entry is made in one or the other field. If the Title field is empty, then only the RequiredFieldValidator will fire and none of the error messages for the DropDownList or the TextBox will fire.

This holds true for Edit mode or Insert mode.

I hope this helps others understand a bit better what is happening and when to expect the CustomValidators to fire.

rweiler

I was having the same issue

And did read my previous answer?

[RESOLVED]Databind to an accordian control VB.NET

I need to bind data to an accordion control. I have 2 tables ‘LinksCategory’ and ‘Links’. The LinksCategory table has a LinkCategoryID field which is referenced in the Links table. I want to group the links under the LinksCategory in the accordion with the
LinksCategory as the header and the associated links under each header.

thanks all

 

Thanks for your quick response.

Not quite what I was after. I was looking to use the asp:accordion control from the ajax toolkit. Also I’m on a closed network so can’t reference external scripts.

there will also be multiple records under each heading.

thanks

 

Hi,

Please refer to the below code:

AccordionPane ap1 = new AccordionPane();
                 ap1.ID = "Pane1";
                 ap1.HeaderContainer.Controls.Add(new LiteralControl("Using Markup"));
                 ap1.ContentContainer.Controls.Add(new
                 LiteralControl("Adding panes using markup is really simple."));
                 AccordionPane ap2 = new AccordionPane();
                 ap2.ID = "Pane2";
                 ap2.HeaderContainer.Controls.Add(new LiteralControl("Using Code"));
                 ap2.ContentContainer.Controls.Add(new
                 LiteralControl("Adding panes using code is really flexible."));
                 acc1.Panes.Add(ap1);
                 acc1.Panes.Add(ap2);

[RESOLVED]Dynamically Created Buttons Won't fire Event Handler

I have created buttons dynammicaly in a gridview from a sql table.

I am trying to get the button click to fire an event on click. Since the buttons are created dynamically I used the AddHandler .

Right now I am just trying to popluate a literal with dummy text; But the end result will be firing java script that loads a bootstrap modal with a edit gridview.

Here is a snip of the two areas in question:

For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)

                    Dim lb As New Button()
                    lb.CommandName = "edit"


                    lb.Text = "Edit"

                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("title", "Edit This Bill")
                        lb.Attributes.Add("class", "btn-mini btn-primary")
                        AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next


    Sub lb_Click(ByVal sender As Object, ByVal e As System.EventArgs)


        Literal4.Text = "Hello World"
        'ClientScript.RegisterStartupScript([GetType](), "Show", "<script> $('#myModal').modal('toggle');</script>")

    End Sub

Here is the whole thing

Imports System
Imports System.Data
Imports System.Data.SqlClient


Public Class WebForm1
    Inherits System.Web.UI.Page
    Public Property DisplayD As String
    Public Property Display As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        'Create the action of the dropdown menu to select the desired month

        If DropDownList1.SelectedItem.Value = "0" Then
            Dim tb2 As New Literal
            For value As Integer = 1 To 3
                tb2 = FindControl("Literal" & value)
                tb2.Text = String.Format("")
            Next
        Else



        End If
        con = GetConnect()
        con.Open()
        Dim month = DropDownList1.SelectedItem.Value()
        'Value for the month is populated here

        'The following gets the data from the database to the gridviews 



        Dim gv As GridView
        Dim tb As Literal
        For value As Integer = 1 To 6
            Dim gvd As New DataDisplay
            If value < 4 Then
                gvd.Name = "gvd" & value
                gvd.Display = "p_DisplayBills2"
                gvd.DisplayD = String.Format("p_DisplayBills2 {0}, {1}", month, value)

            End If
            If value > 3 And value < 7 Then
                Dim cal As Integer = value - 3
                gvd.Name = "gvd" & value
                gvd.Display = "p_CalulatePayPerBills"
                gvd.DisplayD = String.Format("p_CalulatePayPerBills {0}, {1}", month, cal)
            End If
            gv = FindControl("GridView" & value)
            gv.DataSource = gvd.DataDisplay()
            gv.DataBind()

            If value < 4 Then
                Dim rows1 As Integer
                Dim rows2 As Integer
                Dim rows3 As Integer
                If value = 1 Then
                    rows1 = gv.Rows.Count()
                End If
                If value = 2 Then
                    rows2 = gv.Rows.Count()
                End If
                If value = 3 Then
                    rows3 = gv.Rows.Count()
                End If
                Dim arow As Integer() = {rows1, rows2, rows3}
                Dim larrow As Integer = arow.Max()


                If gv.Rows.Count() < larrow Then
                    Dim ds1 As DataSet = gvd.DataDisplay()
                    Dim x As Integer = larrow - gv.Rows.Count()

                    For i As Integer = 1 To x

                        Dim dr = ds1.Tables(0).NewRow()
                        ds1.Tables(0).Rows.Add(dr)

                    Next
                    gv.DataSource = ds1.Tables(0)
                    gv.DataBind()

                End If
            End If

            If value < 4 Then
                For Each oItem As GridViewRow In gv.Rows
                    Dim getFirstColValue As String = oItem.Cells(1).Text
                    oItem.Attributes.Add("id", getFirstColValue)
                Next

                For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)

                    Dim lb As New Button()
                    lb.CommandName = "edit"


                    lb.Text = "Edit"

                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("title", "Edit This Bill")
                        lb.Attributes.Add("class", "btn-mini btn-primary")
                        AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next
            End If
            If value > 3 Then
                For Each fixit As GridViewRow In gv.Rows
                    Dim celltext As String = String.Format(fixit.Cells(0).Text)
                    If celltext = "&nbsp;" Then
                        gv.DataSource = Nothing
                        gv.DataBind()

                    End If
                Next
            End If
            gv.Attributes.Add("class", "table table-condensed table-hover table-bordered table-striped")
            If gv.Rows.Count > 0 And value < 4 Then
                gv.HeaderRow.Cells(0).Text = ""
                gv.HeaderRow.Cells(1).Text = "Bill Name"
                gv.HeaderRow.Cells(3).Text = "Bill Pay Status"
            End If
            If gv.Rows.Count > 0 And value > 3 And value < 7 Then
                Dim totaltext As Integer = value - 3
                gv.HeaderRow.Cells(0).Text = String.Format("Total Pay Period {0}", totaltext)
            End If
            If month > 0 Then
                If value = 1 Or value = 2 Then
                    tb = FindControl("Literal" & value)
                    tb.Text = String.Format("<p>Pay Period: {0}</p>", value)
                End If
                If value = 3 Then

                    tb = FindControl("Literal" & value)
                    tb.Text = String.Format("<p>Pay Period: {0} and Credit Card Bills</p>", value)
                End If
            End If
        Next

    End Sub
    Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.DataRow Then

            e.Row.Cells(2).Attributes.Add("Class", "table-right")

        End If


    End Sub
    Sub lb_Click(ByVal sender As Object, ByVal e As System.EventArgs)


        Literal4.Text = "Hello World"
        'ClientScript.RegisterStartupScript([GetType](), "Show", "<script> $('#myModal').modal('toggle');</script>")

    End Sub
End Class

When using CommandName, you don’t need click event. The button fired with GridView RowCommand event. To add javascript, set lb.OnClientClick="… "

Thankyou so much for your help…

The problem I am having is I also need to fire an event that will eventally poplulate a gridview inside of the javascript modal I am popping up…

Right now I am just trying to measure success by a literal being popluated when the button is clicked…

<p> <asp:Literal ID="Literal4" runat="server"></asp:Literal></p>
    Sub edit_Click(ByVal sender As Object, ByVal e As GridViewCommandEventArgs)

        ' Display the value of the HiddenField control.
        'Dim test = 4
        Literal4.Text = "Hello World"
        'ClientScript.RegisterStartupScript([GetType](), "Show", "<script> $('#myModal').modal('toggle');</script>")

    End Sub

Here is the Grid View code too:

<asp:GridView ID="GridView1" runat="server"  OnRowDataBound="GridView_RowDataBound" OnRowCommand="edit_click">

                    </asp:GridView>

Move your code from edit_Click event to GridView RowEditing event.

I’ve tried this too ways one as a linkbutton using the gridview row editting event as follows in snippet one; and the other as a plain button with a add handler event as follows in snippet two…

Neither way worked…

snippet one:

<asp:Literal ID="Literal1" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView1" runat="server"  OnRowDataBound="GridView_RowDataBound" OnRowEditing="edit_click">

                    </asp:GridView>

 For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)

                    Dim lb As LinkButton = New LinkButton
                    lb.CommandName = "edit"
                    lb.Text = "Edit"

                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("title", "Edit This Bill")
                        lb.Attributes.Add("class", "btn-mini btn-primary")
                        'AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next

  Sub edit_click(ByVal sender As Object, ByVal e As GridViewEditEventArgs)


        Literal4.Text = "Hello World"
        'ClientScript.RegisterStartupScript([GetType](), "Show", "<script> $('#myModal').modal('toggle');</script>")

    End Sub

snippet two

   <asp:Literal ID="Literal1" runat="server"></asp:Literal>  
                    <asp:GridView ID="GridView1" runat="server"  OnRowDataBound="GridView_RowDataBound">

                    </asp:GridView>


                For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)

                    Dim lb As Button = New Button
                    lb.Text = "Edit"
                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("title", "Edit This Bill")
                        lb.Attributes.Add("class", "btn-mini btn-primary")
                        AddHandler lb.Click, AddressOf edit_click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next

  Sub edit_click(ByVal sender As Object, ByVal e As System.EventArgs)


        Literal4.Text = "Hello World"
        'ClientScript.RegisterStartupScript([GetType](), "Show", "<script> $('#myModal').modal('toggle');</script>")

    End Sub

Just a thought but could it be that because the gridviews are created during dropdown1_SelectedIndexChanged event is what is causing my second event not to fire?

Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged

For trouble shooting sake I make the gridviews load on the page load event instead of the dropdownlist_1SelectedIndexChanged Event and the button click event worked…. So am at a loss of what to do. 

I think it might have something to do with the IsPostBack property. I am not sure where to put it though???

[RESOLVED]Pass Gridview Data to BootStrap Java Script Popup Modal

I am building a Budget program using ASP.net and SQL with bootstrap as my display method.

I have successully populated my gridviews with sql data from the codebehind.

I also have successully made the bootstrap modal window popup when you click the edit button.

Right now I have assigned the data I want to pass as the value attibute of the edit button. This is the primary key for the data I will need to edit in the popup modal.  I will have the modal have a gridview that selects the row with that key from the sql
table.

Where I am stuck is passing data into the modal on the edit button click event… 

Here is how I am trying to generate the click event:

For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)
                    Dim lb As LinkButton = New LinkButton
                    lb.CommandName = "edit"
                    lb.Text = "Edit"
                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("value", lbid)
                        lb.Attributes.Add("name", "edit")
                        lb.Attributes.Add("data-toggle", "modal")
                        lb.Attributes.Add("data-target", "#myModal")
                        AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next

    
Private Sub lb_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim updateid As String = "testing one two three"
        Literal4.Text = String.Format("{0}", updateid)

    End Sub

Here is the entire project code for reference:

ASPX page

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="WebForm1.aspx.vb" Inherits="Budget.WebForm1" %>

<!DOCTYPE html>

<html>
<head runat="server">
    <title></title>
    <!-- Le styles -->
    <link href="../css/bootstrap.css" rel="stylesheet">
    <style type="text/css">
      body {
        padding-top: 60px;
        padding-bottom: 40px;
      }
.table-right 
      {
          text-align: right !important;
      }
    </style>
    <link href="../css/bootstrap-responsive.css" rel="stylesheet">
</head>
<body>
    <div class="container">
        <form id="form1" runat="server" value="1">
        <p>Pick a month to update:&nbsp;
        <asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" AutoPostBack="True" 
            DataSourceID="SqlDataSource1" DataTextField="X" DataValueField="MY_ID">
            <asp:ListItem Selected="True" Value="0">Select Month</asp:ListItem>
          
        </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
            ConnectionString="<%$ ConnectionStrings:BudgetConnectionString %>" 
            SelectCommand="p_DisplayMonths" SelectCommandType="StoredProcedure">
        </asp:SqlDataSource>
        </p>
            <div class="row">
            
                <div class="span4">
                   
                    <asp:Literal ID="Literal1" runat="server"></asp:Literal>  
                    <asp:GridView ID="GridView1" runat="server"  OnRowDataBound="GridView_RowDataBound"  >
                    </asp:GridView>
                    <asp:GridView ID="GridView4" runat="server" >
                  
                    </asp:GridView>

                    
                </div>

                <div class="span4">
                    <asp:Literal ID="Literal2" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView2" runat="server" OnRowDataBound="GridView_RowDataBound"  >
                    </asp:GridView>
                    <asp:GridView ID="GridView5" runat="server" >
                  
                    </asp:GridView>
                </div>

                <div class="span4">
                    <asp:Literal ID="Literal3" runat="server"></asp:Literal>
                    <asp:GridView ID="GridView3" runat="server" >
                    </asp:GridView>
                    <asp:GridView ID="GridView6" runat="server" >
                  
                    </asp:GridView>
                </div>

            </div>
        </form>
    </div>
        <script src="http://code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
   <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Modal header</h3>
  </div>
  <div class="modal-body">
    <p><asp:Literal ID="Literal4" runat="server"></asp:Literal></p>
    <p>test</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>
   
    </body>
</html>

Codebehind

Imports System
Imports System.Data
Imports System.Data.SqlClient


Public Class WebForm1
    Inherits System.Web.UI.Page
    Public Property DisplayD As String
    Public Property Display As String

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load


    End Sub

    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        'Create the action of the dropdown menu to select the desired month

        If DropDownList1.SelectedItem.Value = "0" Then
            Dim tb2 As New Literal
            For value As Integer = 1 To 3
                tb2 = FindControl("Literal" & value)
                tb2.Text = String.Format("")
            Next
        Else



        End If
        con = GetConnect()
        con.Open()
        Dim month = DropDownList1.SelectedItem.Value()
        'Value for the month is populated here

        'The following gets the data from the database to the gridviews 



        Dim gv As GridView
        Dim tb As Literal
        For value As Integer = 1 To 6
            Dim gvd As New DataDisplay
            If value < 4 Then
                gvd.Name = "gvd" & value
                gvd.Display = "p_DisplayBills2"
                gvd.DisplayD = String.Format("p_DisplayBills2 {0}, {1}", month, value)

            End If
            If value > 3 And value < 7 Then
                Dim cal As Integer = value - 3
                gvd.Name = "gvd" & value
                gvd.Display = "p_CalulatePayPerBills"
                gvd.DisplayD = String.Format("p_CalulatePayPerBills {0}, {1}", month, cal)
            End If
            gv = FindControl("GridView" & value)
            gv.DataSource = gvd.DataDisplay()
            gv.DataBind()

            If value < 4 Then
                Dim rows1 As Integer
                Dim rows2 As Integer
                Dim rows3 As Integer
                If value = 1 Then
                    rows1 = gv.Rows.Count()
                End If
                If value = 2 Then
                    rows2 = gv.Rows.Count()
                End If
                If value = 3 Then
                    rows3 = gv.Rows.Count()
                End If
                Dim arow As Integer() = {rows1, rows2, rows3}
                Dim larrow As Integer = arow.Max()


                If gv.Rows.Count() < larrow Then
                    Dim ds1 As DataSet = gvd.DataDisplay()
                    Dim x As Integer = larrow - gv.Rows.Count()

                    For i As Integer = 1 To x

                        Dim dr = ds1.Tables(0).NewRow()
                        ds1.Tables(0).Rows.Add(dr)

                    Next
                    gv.DataSource = ds1.Tables(0)
                    gv.DataBind()

                End If
            End If

            If value < 4 Then
                For Each oItem As GridViewRow In gv.Rows
                    Dim getFirstColValue As String = oItem.Cells(1).Text
                    oItem.Attributes.Add("id", getFirstColValue)
                Next

               
                For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)
                    Dim lb As LinkButton = New LinkButton
                    lb.CommandName = "edit"
                    lb.Text = "Edit"
                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("value", lbid)
                        lb.Attributes.Add("name", "edit")
                        lb.Attributes.Add("data-toggle", "modal")
                        lb.Attributes.Add("data-target", "#myModal")
                        AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next
            End If
            If value > 3 Then
                For Each fixit As GridViewRow In gv.Rows
                    Dim celltext As String = String.Format(fixit.Cells(0).Text)
                    If celltext = "&nbsp;" Then
                        gv.DataSource = Nothing
                        gv.DataBind()

                    End If
                Next
            End If
            gv.Attributes.Add("class", "table table-condensed table-hover table-bordered table-striped")
            If gv.Rows.Count > 0 And value < 4 Then
                gv.HeaderRow.Cells(0).Text = ""
                gv.HeaderRow.Cells(1).Text = "Bill Name"
                gv.HeaderRow.Cells(3).Text = "Bill Pay Status"
            End If
            If gv.Rows.Count > 0 And value > 3 And value < 7 Then
                Dim totaltext As Integer = value - 3
                gv.HeaderRow.Cells(0).Text = String.Format("Total Pay Period {0}", totaltext)
            End If
            If month > 0 Then
                If value = 1 Or value = 2 Then
                    tb = FindControl("Literal" & value)
                    tb.Text = String.Format("<p>Pay Period: {0}</p>", value)
                End If
                If value = 3 Then

                    tb = FindControl("Literal" & value)
                    tb.Text = String.Format("<p>Pay Period: {0} and Credit Card Bills</p>", value)
                End If
            End If
        Next





    End Sub
    Sub GridView_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

        If e.Row.RowType = DataControlRowType.DataRow Then

            e.Row.Cells(2).Attributes.Add("Class", "table-right")
            'e.Row.Cells(1).Text = "<i>" & e.Row.Cells(1).Text & "</i>"

        End If


    End Sub
    Private Sub lb_Click(ByVal sender As Object, ByVal e As EventArgs)

        Dim updateid As String = "testing one two three"


        Literal4.Text = String.Format("{0}", updateid)

    End Sub

End Class

I seemed to have found my answer for getting the data to the Java Script Modal…
Now I just need to pass that into a gridview in the modal??? I’m thinking event handler of some sort? 

Here is what I did…
I added this script to poplate the modal…

<script>        $(document).on("click", ".open-myModal", function () {
            var BillId = $(this).data('id');
            $(".modal-body #BillId").val(BillId);
        });</script>
   <div id="myModal" class="modal hide fade" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
  <div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
    <h3 id="myModalLabel">Update Bill Information</h3>
  </div>
  <div class="modal-body">
    <p><asp:Literal ID="Literal4" runat="server"></asp:Literal></p>
    <input type="text" name="BillId" id="BillId" value=""/>
    <p>This will be the future spot to update information about a bill</p>
  </div>
  <div class="modal-footer">
    <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    <button class="btn btn-primary">Save changes</button>
  </div>
</div>

And then I adjusted the code behind to use a hyper link instead of a linkbutton…

For Each commanditem As GridViewRow In gv.Rows
                    Dim lbid As String = String.Format(commanditem.Cells(0).Text)
                    Dim lb As HyperLink = New HyperLink
                    'lb.CommandName = "edit"
                    lb.NavigateUrl = "#myModal"
                    lb.Text = "Edit"
                    Dim lbval As Integer
                    If Integer.TryParse(lbid, lbval) Then
                        lbval = Convert.ToInt32(lbid)
                    End If

                    If lbval > 0 Then
                        lb.Attributes.Add("data-id", lbid)
                        lb.Attributes.Add("title", "Add this item")
                        lb.Attributes.Add("class", "open-myModal btn-mini btn-primary")
                        lb.Attributes.Add("data-toggle", "modal")
                        'lb.Attributes.Add("data-target", "#myModal")
                        'AddHandler lb.Click, AddressOf lb_Click
                        commanditem.Cells(0).Controls.Add(lb)
                    End If
                Next

 

Hi,

I am very glad that you have solved your problem by yourself.

If you have any other problem, welcome to post it in the asp.net forums.

Best Regards.

Hi,

I am very glad that you have solved your problem by yourself.

If you have any other problem, welcome to post it in the asp.net forums.

Best Regards,
Amy Peng