我想在按钮上更改按钮文本后保持不变

时间:2017-03-29 10:07:44

标签: c# asp.net sql-server

我正在处理我的项目,其中我有一个网格视图,其中有一个状态字段,其中包含按钮。 当用户单击该按钮时,该按钮的文本将从挂起更改为确认。 问题是,当我关闭浏览器并通过visual studio再次加载.aspx页面时,按钮的文本再次设置为待定,这是我不想要的。 任何人都可以告诉我如何保持按钮文本仅在单击按钮时确认,并且当我单击第一行状态字段按钮时,所有其余状态字段都会在数据库中更新并确认状态。 这是我的代码:(前端代码)

btVector3 vertex1, vertex2, vertex3, vertex4;
btTriangleMesh* triangleMeshTerrain = new btTriangleMesh();

for (int i = -250; i < 250; i = i + 10) {
    for (int j = -250; j < 250; j = j + 10) {

        vertex1 = btVector3(i, 0.0f, j);
        vertex2 = btVector3(i + 10.0f, 0.0f, j);
        vertex3 = btVector3(i + 10.0f, 0.0f, j + 10.0f);
        vertex4 = btVector3(i, 0.0f, j + 10.0f);

        triangleMeshTerrain->addTriangle(vertex1, vertex2, vertex3);
        triangleMeshTerrain->addTriangle(vertex1, vertex3, vertex4);
    }
}

btCollisionShape* collisionShapeTerrain = new btBvhTriangleMeshShape(triangleMeshTerrain, true);

btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(0, 0, 0, 1), btVector3(0, -15, 0)));

btRigidBody::btRigidBodyConstructionInfo rigidBodyConstructionInfo(0.0f, motionState, collisionShapeTerrain, btVector3(0, 0, 0));
btRigidBody* rigidBodyTerrain = new btRigidBody(rigidBodyConstructionInfo);
rigidBodyTerrain->setFriction(btScalar(0.9));

m_dynamicsWorld->addRigidBody(rigidBodyTerrain);

(后端代码):

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand"
    Font-Bold="True" Font-Size="Small" GridLines="None">
    <Columns>
        <asp:BoundField ItemStyle-Width="150px" DataField="packagename" HeaderText="Package" />
        <asp:BoundField ItemStyle-Width="150px" DataField="name" HeaderText="Name" />
        <asp:BoundField ItemStyle-Width="150px" DataField="gender" HeaderText="Gender" />
        <asp:BoundField ItemStyle-Width="150px" DataField="mobileno" HeaderText="Mobile No" />
        <asp:BoundField ItemStyle-Width="150px" DataField="email" HeaderText="Email" />
        <asp:BoundField ItemStyle-Width="150px" DataField="noofdays" HeaderText="No. of Days" />
        <asp:BoundField ItemStyle-Width="150px" DataField="child" HeaderText="No. of Children" />
        <asp:BoundField ItemStyle-Width="150px" DataField="adults" HeaderText="No of Adults" />
        <asp:TemplateField HeaderText="Status Field">
            <ItemTemplate>
                <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="MYCOMMAND"
                    Text="Pending" BorderStyle="None" Font-Bold="True" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

1 个答案:

答案 0 :(得分:0)

您可以使用asp.net中的Bind功能,这样您的按钮文本将从DB结果中获取。如下。

在aspx页面

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="GridView1_RowCommand"
    Font-Bold="True" Font-Size="Small" GridLines="None">
    <Columns>
        <asp:BoundField ItemStyle-Width="150px" DataField="enquiryid" HeaderText="Enquiryid" />
        <asp:BoundField ItemStyle-Width="150px" DataField="packagename" HeaderText="Package" />
        <asp:BoundField ItemStyle-Width="150px" DataField="name" HeaderText="Name" />
        <asp:BoundField ItemStyle-Width="150px" DataField="gender" HeaderText="Gender" />
        <asp:BoundField ItemStyle-Width="150px" DataField="mobileno" HeaderText="Mobile No" />
        <asp:BoundField ItemStyle-Width="150px" DataField="email" HeaderText="Email" />
        <asp:BoundField ItemStyle-Width="150px" DataField="noofdays" HeaderText="No. of Days" />
        <asp:BoundField ItemStyle-Width="150px" DataField="child" HeaderText="No. of Children" />
        <asp:BoundField ItemStyle-Width="150px" DataField="adults" HeaderText="No of Adults" />
        <asp:TemplateField HeaderText="Status Field">
            <ItemTemplate>
                <asp:Button ID="Button1" runat="server" CausesValidation="false" CommandName="MYCOMMAND"
                    Text='<%# Bind("statusfield")%>' BorderStyle="None" Font-Bold="True" />
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

在.cs文件中修改BindGrid方法,以便它可以返回状态字段列。

 private void BindGrid()
{

   using (SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=D:\PROJECT SEM6\Online Tours and Travels\App_Data\ToursandTravels.mdf;Integrated Security=True;User Instance=True"))
    {

    using (SqlCommand cmd = new SqlCommand("SELECT enquiryid,packagename,name, gender,mobileno,email,noofdays,child,adults,statusfield FROM enquiry"))
        {
            using (SqlDataAdapter sda = new SqlDataAdapter())
            {
                cmd.Connection = con;
                sda.SelectCommand = cmd;
                using (DataTable dt = new DataTable())
                {
                    sda.Fill(dt);
                    GridView1.DataSource = dt;
                    GridView1.DataBind();
                }
            }
        }
    }
}