根据gridview中选定的行打开不同的模态框

时间:2015-12-18 12:58:17

标签: javascript asp.net vb.net modal-dialog

我有一个包含很多行的gridview,这些行可以有两个不同的含义。根据行的含义,我需要打开一个不同的模态poupup,有人可以解释我该怎么做?

这是gridview的代码:

<asp:GridView ID="grd_elenco" runat="server" data-toggle="modal" data-target="#myModal1">

这就是我创建模态框的方式:

<div id="#myModal1" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">&times;</button>
                <h4 class="modal-title">Titolo</h4>
            </div>
            <div class="modal-body">

                         <!--my content-->

            </div>
            <div class="modal-footer">
                <asp:Button runat="server" type="button" Text="Chiudi" class="btn btn-default" data-dismiss="modal" />
            </div>
        </div>
    </div>
</div>

所以,我需要以编程方式进行更改,并根据行的内容进行gridview的数据目标,是否可能?

1 个答案:

答案 0 :(得分:0)

我用这段代码解决了我的问题:

VB.NET

Private Sub grd_elenco_RowDataBound(sender As Object, e As GridViewRowEventArgs) Handles grd_elenco.RowDataBound
    Dim variable As Integer = Convert.ToInt32(DataBinder.Eval(e.Row.DataItem, "column_name")) 'take the value from column
    e.Row.Attributes.Add("OnClick", "OpenModalBox(" + variable.ToString + ")")
End Sub

的Javascript

function OpenModalBox(variable) {
    if (variable==0){
        $('#mymodal1').modal('show');
    } else {
        $('#mymodal2').modal('show');
    }
}