C# 值不显示在我的模式中

C# 值不显示在我的模式中,c#,jquery,asp.net,gridview,bootstrap-modal,C#,Jquery,Asp.net,Gridview,Bootstrap Modal,文本框的值不会出现。我的代码怎么了?显示模式,但它不获取表的值。我对它做了一个命令并把代码放在那里。但是没有演出。谁能帮帮我吗 谢谢大家! 这是我的.cs代码 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int i = Convert.ToInt32(e.CommandArgument); GridViewRow gvrow = Gr

文本框的值不会出现。我的代码怎么了?显示模式,但它不获取表的值。我对它做了一个命令并把代码放在那里。但是没有演出。谁能帮帮我吗

谢谢大家!

这是我的.cs代码

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);


    }
protectedvoid GridView1\u行命令(对象发送方,GridViewCommandEventArgs e)
{
inti=Convert.ToInt32(如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]。单元格[0]。Text.ToString();
lblResult.Visible=false;
System.Text.StringBuilder sb=新的System.Text.StringBuilder();
某人加上(@“);
sb.追加($('#editmodel').model('show'););
某人加上(@“);
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“EditModalScript”,sb.ToString(),false);
}
这是我的模态div代码

<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>

x
查看详细信息
项目ID:
类型:
型号:
申请数量:
单位:
所需日期:
说明:
接近
我的GRIDVIEW 1的标记

<asp:UpdatePanel ID="panel1" runat="server">
     <ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="TransactionID" OnRowDataBound="GridView1_OnRowDataBound" OnRowCommand="GridView1_RowCommand" CellPadding="4" AllowPaging="true" PageIndex="2" OnPageIndexChanging="GridView1_PageIndexChanging" HeaderStyle-BackColor ="CornflowerBlue" BorderWidth="1" BorderColor="Gray" Width="100%" CssClass=" table table-hover" >
    <Columns>
        <asp:TemplateField>
            <ItemTemplate>
                <asp:CheckBox ID="chkSelect" runat="server"  />
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField>
            <ItemTemplate>
                <img style="cursor:pointer" src ="../Images/Icons/plus2.png" />
                <asp:Panel ID ="pnlDetails" runat="server" Style="display: none">
                    <asp:GridView ID="gvDet" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
                        <Columns>
                            <%--<asp:BoundField ItemStyle-Width="20px" DataField="ID" HeaderText="ID" />--%>
                            <asp:BoundField ItemStyle-Width="200px" DataField="ItemType" HeaderText="Type" />
                            <asp:BoundField ItemStyle-Width="250px" DataField="ItemModel" HeaderText="Model" />
                            <asp:BoundField ItemStyle-Width="140px" DataField="ItemQuantity" HeaderText="Requested Quantity" />
                            <asp:BoundField ItemStyle-Width="80px" DataField="ItemUnit" HeaderText="Unit" />
                            <asp:BoundField ItemStyle-Width="100px" DataField="ItemDate" HeaderText="Date Needed" />
                            <asp:BoundField ItemStyle-Width="200px" DataField="ItemDesc" HeaderText="Description" />
                            <%--<asp:BoundField ItemStyle-Width="80px" DataField="ItemStatus" HeaderText="Status" />--%>
                        </Columns>
                    </asp:GridView>
                </asp:Panel>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Transaction Number" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblmosID" runat="server" Text='<%#Bind ("TransactionID") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Width="30px" Font-Size="15px" Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Date" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblDate" runat="server" Text='<%#Bind ("DateFiled") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Width="130px" Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Name" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblName" runat="server" Text='<%#Bind ("ReqName") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Company" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblComp" runat="server" Text='<%#Bind ("ReqCompany") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Branch" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblBranch" runat="server" Text='<%#Bind ("ReqBranch") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names ="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Business Unit" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblBU" runat="server" Text='<%#Bind ("ReqBU") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Department" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblDept" runat="server" Text='<%#Bind ("ReqDept") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Section" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblsection" runat="server" Text='<%#Bind ("ReqSection") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Status" HeaderStyle-ForeColor="White">
            <ItemTemplate>
                <asp:Label ID ="lblStatus" runat="server" Text='<%#Bind ("TransStatus") %>'></asp:Label>
            </ItemTemplate>
            <ItemStyle Font-Names="Calibri" />
        </asp:TemplateField>
        <%--<asp:TemplateField HeaderText="">
            <ItemTemplate>
                <asp:LinkButton ID ="lnkEdit" runat="server" Text="View" PostBackUrl='<%# "Details.aspx?Id=" + Eval("TransactionID") %>'></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>--%>
        <asp:ButtonField CommandName="editRecord" ControlStyle-CssClass="btn btn-info" ButtonType="Button" Text="View" HeaderText="View Request" HeaderStyle-ForeColor="White">
        <ControlStyle CssClass ="btn btn-info" />    
        </asp:ButtonField>
    </Columns>
    <HeaderStyle BackColor="CornflowerBlue" />
</asp:GridView>
         </ContentTemplate>
     <Triggers>
         <asp:AsyncPostBackTrigger ControlID="GridView1" />
     </Triggers>
     </asp:UpdatePanel>

--%>
我的代码怎么了


谢谢

我已经尝试在我这边重新创建您的问题,但它似乎有效。我的代码中唯一的主要区别是我在
GridView上使用了
AutoGenerateSelectButton=“True”
EnableCdn=“True”
ScriptManager
控件上。查看下面的代码,看看您是否能发现您的逻辑不正常的地方,并找出您的逻辑不正常的原因。我希望它能对您有所帮助

代码隐藏:

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; }
}
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <asp:ScriptManager ID="ScriptManager1" runat="server" EnableCdn="true"></asp:ScriptManager>
        <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" />
                                <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>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <asp:GridView ID="GridView1" runat="server" OnRowCommand="GridView1_RowCommand" AutoGenerateSelectButton="True">
                </asp:GridView>
            </ContentTemplate>
            <Triggers>
             <asp:AsyncPostBackTrigger ControlID="GridView1" />
         </Triggers>
        </asp:UpdatePanel>
    </form>
</body>
</html>
public分部类DisplayGridViewRowInPopup:System.Web.UI.Page
{
受保护的无效页面加载(对象发送方、事件参数e)
{
如果(!Page.IsPostBack)
{
GetData();
}
}
public void GetData()
{
变量p1=新产品{TransactionID=1,ItemType=“Type1”,ItemModel=“Model1”,ItemQuantity=1,ItemUnit=“Unit1”,ItemDate=DateTime。现在,ItemDesc=“产品1”};
var p2=新产品{TransactionID=2,ItemType=“Type2”,ItemModel=“Model2”,ItemQuantity=2,ItemUnit=“Unit2”,ItemDate=DateTime。现在,ItemDesc=“产品2”};
GridView1.DataSource=新列表{p1,p2};
GridView1.DataBind();
}
受保护的void GridView1_row命令(对象发送方,GridViewCommandEventArgs e)
{
inti=Convert.ToInt32(如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;
字符串脚本=“$('#editmodel').model('show');”;
ScriptManager.RegisterClientScriptBlock(this,this.GetType(),“EditModalScript”,script,false);
}
}
公共类产品
{
public int TransactionID{get;set;}
公共字符串ItemType{get;set;}
公共字符串ItemModel{get;set;}
公共int ItemQuantity{get;set;}
公共字符串ItemUnit{get;set;}
公开日期