Use the button defined behind in C# in front bootstrap modal

心不动则不痛 提交于 2019-12-12 02:44:38

问题


I write this to have a floating window shows up after I click open modal button

 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>
    <div id="myModal" class="modal fade" role="dialog">
        <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">Modal Header</h4>

                </div>
                <div class="modal-body" id="imghere">
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

in this example, I defined the button with

 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>

Now I have a button defined in C# loop in behind

protected void GenGridView()
    {
        var data = project.ObtainDataDescJSON();
        Title = "show";
        for (int rowCtr = 0; row < data.Num.Count; row++)
        {
            var buttonField = new ButtonField
            {
                ButtonType = ButtonType.Button,
                Text = "Show",
                CommandName = "Display"

            };
            ModelNumFieldsGrid.Columns.Add(buttonField);
            break;
        }
      }

How can I use these buttons I defined in C# in the bootstrap modal? How should I change the

 <button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">Open Modal</button>

should I use something like get element By ID? I really new to Web developing, please help! Thanks


回答1:


You could just use a regular button, not a button field but either way this should do it. Or you can just use jQuery to find all of the buttons you added and attach the attributes that way (preferred).

protected void GenGridView()
    {
        var data = project.ObtainDataDescJSON();
        Title = "show";
        for (int rowCtr = 0; row < data.Num.Count; row++)
        {
            var buttonField = new ButtonField
            {
                ButtonType = ButtonType.Button,
                Text = "Show",
                CommandName = "Display"

            };

            buttonField.Attributes.Add("data-toggle", "modal");
            buttonField.Attributes.Add("data-target", "#myModal");
            buttonField.CssClass = "btn btn-info";             

            ModelNumFieldsGrid.Columns.Add(buttonField);
            break;
        }
      }


来源:https://stackoverflow.com/questions/33217284/use-the-button-defined-behind-in-c-sharp-in-front-bootstrap-modal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!