从字符串中获取值或在数据库中存储?

时间:2016-05-28 13:22:15

标签: asp.net button gridview boundfield rowcommand

这是我的viewcreditrequest html页面:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" 
    CssClass="table table-hover table-striped" OnRowCommand="GridView1_RowCommand"
    onselectedindexchanged="GridView1_SelectedIndexChanged">
    <Columns>

           <asp:BoundField DataField="Username" HeaderText="Username" 
            SortExpression="Username" />

        <asp:BoundField DataField="LastName" HeaderText="LastName" 
            SortExpression="LastName" />

        <asp:BoundField DataField="FirstName" HeaderText="FirstName" 
            SortExpression="FirstName" />

        <asp:BoundField DataField="CompanyName" HeaderText="CompanyName" 
            SortExpression="CompanyName" />

        <asp:BoundField DataField="EmailAddress" HeaderText="EmailAddress" 
            SortExpression="EmailAddress" />

        <asp:BoundField DataField="CompanyAddress" HeaderText="CompanyAddress" 
            SortExpression="CompanyAddress" />

        <asp:BoundField DataField="IncomeRange" HeaderText="IncomeRange" 
            SortExpression="IncomeRange" />

        <asp:BoundField DataField="CreditRequest" HeaderText="CreditRequest" 
            SortExpression="CreditRequest" />

        <asp:BoundField DataField="ContactNumber" HeaderText="ContactNumber" SortExpression="ContactNumber" />

        <asp:TemplateField>
                <ItemTemplate>
                    <asp:Button ID="Button1" runat="server" Text="Approve" CommandName="Approve" CommandArgument='<%# Eval("CreditRequest") %>' />
                </ItemTemplate>
            </asp:TemplateField>

    </Columns>
</asp:GridView>

和代码背后:

protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            if (Session["IslandGasAdminFM"] != null)
            {

                bindgrid();
                Label1.Text = "- Finance Manager";

            }
            else
            {
                Response.Write("<script>alert('Finance Manager credentials needed'); window.location.href='LogIn.aspx';</script>");
            }
        }
    }


    protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        System.Diagnostics.Debugger.Break();

        if (e.CommandName == "Approve")
        {
            string creditRequest = e.CommandArgument as string;
        }
    }
    public void bindgrid()
    {
        SqlConnection conn = new SqlConnection("Data Source = 'PAULO'; Initial Catalog=ShoppingCartDB;Integrated Security =True");
        SqlCommand cmd = new SqlCommand("select * from CreditRequests ", conn);

        SqlDataAdapter da = new SqlDataAdapter("", conn);
        da.SelectCommand = new SqlCommand("select * from CreditRequests", conn);
        DataSet ds = new DataSet();
        da.Fill(ds, "data");
        GridView1.DataSource = ds.Tables[0].DefaultView;
        GridView1.DataBind();
    }

我想在这里发生的是获得&#34;信用请求的价值&#34;在林地。 bindgrid()工作正常,我也添加了

EnableViewState="false"

到我的gridview。当我点击按钮时,它现在将信用请求的值分配给字符串信用请求。关于如何使其可见或甚至将其存储在数据库中的任何想法?

0 个答案:

没有答案