我的模态中没有显示值

时间:2016-07-04 03:58:57

标签: c# jquery asp.net gridview bootstrap-modal

文本框的值不会出现。我的代码有什么问题?模态显示但它没有得到表的值。我做了一个rowcommand并将代码放在那里。但没有显示。请有人帮帮我。

谢谢!

这是我的.cs代码

app.factory('ContactMessages', [
    function () {
        var o = {};

        o.AddNewContact = {};
        return o;
    }
]);

这是我的模态div代码

protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int i = Convert.ToInt32(e.CommandArgument);



        GridViewRow gvrow = GridView1.Rows[i];
        txtID.Text = gvrow.Cells[0].Text;
        txtType.Text = gvrow.Cells[1].Text;
        txtModel.Text = gvrow.Cells[2].Text;
        txtQuan.Text = HttpUtility.HtmlDecode(gvrow.Cells[3].Text);
        txtUnit.Text = HttpUtility.HtmlDecode(gvrow.Cells[4].Text);
        txtDate.Text = HttpUtility.HtmlDecode(gvrow.Cells[5].Text);
        txtDesc.Text = HttpUtility.HtmlDecode(gvrow.Cells[6].Text);


        //txtID.Text = GridView1.Rows[i].Cells[0].Text.ToString();


            lblResult.Visible = false;

            System.Text.StringBuilder sb = new System.Text.StringBuilder();
            sb.Append(@"<script type='text/javascript'>");
            sb.Append("$('#editModal').modal('show');");
            sb.Append(@"</script>");
            ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditModalScript", sb.ToString(), false);


    }

我的GRIDVIEW 1的标记

<div id="editModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="editModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">x</button>
                <h3 id="editModalLabel">View Details</h3>
            </div>    
<asp:UpdatePanel ID="upEdit" runat="server">
    <ContentTemplate>
        <div class ="modal-body">
            <table class="table">
                <tr>
                    <td>Item ID:
                        <asp:TextBox ID="txtID" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Type:
                        <asp:TextBox ID="txtType" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Model:
                        <asp:TextBox ID="txtModel" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Requested Quantity:
                        <asp:TextBox ID="txtQuan" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Unit:
                        <asp:TextBox ID="txtUnit" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Date Needed:
                        <asp:TextBox ID="txtDate" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>Description:
                        <asp:TextBox ID="txtDesc" runat="server"></asp:TextBox>
                    </td>
                </tr>
            </table>
        </div>
        <div class="modal-footer">
            <asp:Label ID="lblResult" Visible="false" runat="server"></asp:Label>
            <asp:Button ID ="btnSave" runat="server" Text="Approve" CssClass="btn btn-primary" OnClick="btnSave_Click" />
            <button class="btn btn-info" data-dismiss="modal" aria-hidden="true">Close</button>
        </div>
    </ContentTemplate>
    <Triggers>
        <asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
        <asp:AsyncPostBackTrigger ControlID ="btnSave" EventName="Click" />
    </Triggers>
</asp:UpdatePanel>
    </div>
        </div>
    </div>

我的代码有什么问题?

谢谢!

1 个答案:

答案 0 :(得分:0)

我尝试过在我身边重新创建你的问题,但似乎工作正常。我的代码中唯一的主要区别是我在AutoGenerateSelectButton="True"和{{1}上使用了GridViewEnableCdn="true"控件上。看看下面的代码,看看你是否能发现你的逻辑没有做的奇怪的事情,并找出你的工作不起作用的原因。我希望它对你有帮助。

代码背后:

ScriptManager

<强> .ASPX:

public partial class DisplayGridViewRowInPopup : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            GetData();
        }
    }

    public void GetData()
    {
        var p1 = new Product { TransactionID = 1, ItemType = "Type1", ItemModel = "Model1", ItemQuantity = 1, ItemUnit = "Unit1", ItemDate = DateTime.Now, ItemDesc = "Product 1" };
        var p2 = new Product { TransactionID = 2, ItemType = "Type2", ItemModel = "Model2", ItemQuantity = 2, ItemUnit = "Unit2", ItemDate = DateTime.Now, ItemDesc = "Product 2" };
        GridView1.DataSource = new List<Product> { p1, p2 };
        GridView1.DataBind();
    }

    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        int i = Convert.ToInt32(e.CommandArgument);

        GridViewRow gvrow = GridView1.Rows[i];
        txtID.Text = gvrow.Cells[1].Text;
        txtType.Text = gvrow.Cells[2].Text;
        txtModel.Text = gvrow.Cells[3].Text;
        txtQuan.Text = HttpUtility.HtmlDecode(gvrow.Cells[4].Text);
        txtUnit.Text = HttpUtility.HtmlDecode(gvrow.Cells[5].Text);
        txtDate.Text = HttpUtility.HtmlDecode(gvrow.Cells[6].Text);
        txtDesc.Text = HttpUtility.HtmlDecode(gvrow.Cells[7].Text);

        lblResult.Visible = false;
        string script = "<script type='text/javascript'>$('#editModal').modal('show');</script>";
        ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "EditModalScript", script, false);
    }
}

public class Product
{
    public int TransactionID { get; set; }
    public string ItemType { get; set; }
    public string ItemModel { get; set; }
    public int ItemQuantity { get; set; }
    public string ItemUnit { get; set; }
    public DateTime ItemDate { get; set; }
    public string ItemDesc { get; set; }
}

<强>输出:

Displaying GridView row edit template in modal popup