0
<asp:GridView ID="grvStudentDetails" runat="server" 
            ShowFooter="True" AutoGenerateColumns="False"
            CellPadding="4"  
            GridLines="None" OnRowDeleting="grvStudentDetails_RowDeleting">
<Columns>
    <asp:BoundField DataField="RowNumber" HeaderText="" />
    <asp:TemplateField HeaderText="From">
         <ItemTemplate>
            <asp:DropDownList ID="drpQualification" runat="server" >
                <asp:ListItem Value="G">kolkata</asp:ListItem>

                <asp:ListItem Value="P">Mumbai</asp:ListItem>
            </asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="To">
        <ItemTemplate>
           <asp:DropDownList ID="drQualification" runat="server">
                <asp:ListItem Value="G">Bangalore</asp:ListItem>
                <asp:ListItem Value="P">Delhi</asp:ListItem>
            </asp:DropDownList>
        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Travel Date">
        <ItemTemplate>
              <asp:TextBox ID="txtAddress" runat="server" ></asp:TextBox>

        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="">
        <ItemTemplate>

        </ItemTemplate>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="">
        <ItemTemplate>

        </ItemTemplate>
        <FooterStyle HorizontalAlign="Right" />
        <FooterTemplate>
            <asp:Button ID="ButtonAdd" runat="server" 
                    Text="Add New City" OnClick="ButtonAdd_Click" />
        </FooterTemplate>
    </asp:TemplateField>
    <asp:CommandField ShowDeleteButton="True" />
</Columns>

</asp:GridView>

i have the following gridview in my asp page, now i want to connect all the contents means from,to, date etc..of this gridview to my database on click of save button, how i will do this, what all i have to do in my .cs file.PLZZZ HELP

protected void Button1_Click(object sender, EventArgs e)
{
    string insrt = "insert into book_mas_det(book_date,book_from,book_to,travel_date,return_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n)";
    MySqlCommand cmd = new MySqlCommand(insrt, conn);
    cmd.Parameters.AddWithValue("@a", txtbookingdate.Text);
    cmd.Parameters.AddWithValue("@b", ddlfrom.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@c", ddlto.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@d", txtdeprtr.Text);
    cmd.Parameters.AddWithValue("@e", txtreturn.Text);
    cmd.Parameters.AddWithValue("@f", txtadult.Text);
    cmd.Parameters.AddWithValue("@g", txtchild.Text);
    cmd.Parameters.AddWithValue("@h", ddlclass.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@i", txtcontpername.Text);
    cmd.Parameters.AddWithValue("@j", txtcontmobile.Text);
    cmd.Parameters.AddWithValue("@k", txtamnttocharge.Text);
    cmd.Parameters.AddWithValue("@l", txtadvamnt.Text);
    cmd.Parameters.AddWithValue("@m", txtcmnttrav.Text);
    cmd.Parameters.AddWithValue("@n", txtcmntagnt.Text);
    conn.Open();
    cmd.ExecuteNonQuery();
    conn.Close();
    string display = "Booking Details is added successfully";
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);

i have added my .cs code for the view1 connectivity,now how to do the connectivity for view2 and view3

4

3 に答える 3

0

これはあなたを助けるかもしれません..!! これは私のコードです..!!テンプレートフィールドのtexbox IDを置き換えることができます..!! 文字列値をデータベースのテーブルに保存する方法を知っていると思います..!! このコードで十分だと思います.!! 私はあなたから知りたい.. !!

 try
    {
        for (int i = 0; i < gvInvTransaction.Rows.Count - 1; i++)
        {
            TextBox txtproduct = (TextBox)gvInvTransaction.Rows[i].FindControl("txtProduct");
            TextBox txtBarcode = (TextBox)gvInvTransaction.Rows[i].FindControl("txtBarCode");
            TextBox txtPrdctBatchID = (TextBox)gvInvTransaction.Rows[i].FindControl("txtPrdctBatchID");
            TextBox txtPrdctID = (TextBox)gvInvTransaction.Rows[i].FindControl("txtPrdctID");
            TextBox txtStdPurchasePrice = (TextBox)gvInvTransaction.Rows[i].FindControl("txtUnitPrice");
            TextBox txtStdSalesPrice = (TextBox)gvInvTransaction.Rows[i].FindControl("txtUnitPrice");





            string  ProductID = Convert.ToInt64(txtPrdctID.Text);
            string  StdPurchasePrice = Convert.ToDouble(txtStdPurchasePrice.Text);
            string  StdSalesPrice = Convert.ToDouble(txtStdPurchasePrice.Text);







        }
    }
    catch (Exception ex) { }
}
于 2013-11-09T10:14:23.137 に答える
-1

他の 2 つのデータベース挿入用に別の文字列と Sql コマンド オブジェクトを作成し、パラメーターを追加します。パラメーターには、gridview から取得した文字列値を渡し、cmd2.ExecuteNonQuery(); を呼び出します。そしてcmd2.execute..!! 以下は単なるサンプルです。各ビューの値に置き換えてください..!! それが役に立てば幸い..!!:)

 protected void Button1_Click(object sender, EventArgs e)
{
    string insrt = "insert into book_mas_det(book_date,book_from,book_to,travel_date,return_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n)";
    string insrt2 = "insert into book_mas_det(book_date,book_from,book_to,travel_date,return_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n)";
    string insrt3 = "insert into book_mas_det(book_date,book_from,book_to,travel_date,return_date,adult_pax,child_pax,travel_class,contact_name,pnr_no,tot_amt,adv_amount,travler_rmks,agent_rmks) values (@a,@b,@c,@d,@e,@f,@g,@h,@i,@j,@k,@l,@m,@n)";

    MySqlCommand cmd = new MySqlCommand(insrt, conn);
    MySqlCommand cmd2 = new MySqlCommand(insrt2, conn);
    MySqlCommand cmd3 = new MySqlCommand(insrt3, conn);

    //cmd parameters
    cmd.Parameters.AddWithValue("@a", txtbookingdate.Text);
    cmd.Parameters.AddWithValue("@b", ddlfrom.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@c", ddlto.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@d", txtdeprtr.Text);
    cmd.Parameters.AddWithValue("@e", txtreturn.Text);
    cmd.Parameters.AddWithValue("@f", txtadult.Text);
    cmd.Parameters.AddWithValue("@g", txtchild.Text);
    cmd.Parameters.AddWithValue("@h", ddlclass.SelectedItem.Text);
    cmd.Parameters.AddWithValue("@i", txtcontpername.Text);
    cmd.Parameters.AddWithValue("@j", txtcontmobile.Text);
    cmd.Parameters.AddWithValue("@k", txtamnttocharge.Text);
    cmd.Parameters.AddWithValue("@l", txtadvamnt.Text);
    cmd.Parameters.AddWithValue("@m", txtcmnttrav.Text);
    cmd.Parameters.AddWithValue("@n", txtcmntagnt.Text);

   //cmd2 parameters -replace this with your second view values 
    cmd2.Parameters.AddWithValue("@a", txtbookingdate.Text);
    cmd2.Parameters.AddWithValue("@b", ddlfrom.SelectedItem.Text);
    cmd2.Parameters.AddWithValue("@c", ddlto.SelectedItem.Text);
    cmd2.Parameters.AddWithValue("@d", txtdeprtr.Text);
    cmd2.Parameters.AddWithValue("@e", txtreturn.Text);
    cmd2.Parameters.AddWithValue("@f", txtadult.Text);
    cmd2.Parameters.AddWithValue("@g", txtchild.Text);
    cmd2.Parameters.AddWithValue("@h", ddlclass.SelectedItem.Text);
    cmd2.Parameters.AddWithValue("@i", txtcontpername.Text);
    cmd2.Parameters.AddWithValue("@j", txtcontmobile.Text);
    cmd2.Parameters.AddWithValue("@k", txtamnttocharge.Text);
    cmd2.Parameters.AddWithValue("@l", txtadvamnt.Text);
    cmd2.Parameters.AddWithValue("@m", txtcmnttrav.Text);
    cmd2.Parameters.AddWithValue("@n", txtcmntagnt.Text);

   //cmd3 parameters- replace this with your third view values 
    cmd3.Parameters.AddWithValue("@a", txtbookingdate.Text);
    cmd3.Parameters.AddWithValue("@b", ddlfrom.SelectedItem.Text);
    cmd3.Parameters.AddWithValue("@c", ddlto.SelectedItem.Text);
    cmd3.Parameters.AddWithValue("@d", txtdeprtr.Text);
    cmd3.Parameters.AddWithValue("@e", txtreturn.Text);
    cmd3.Parameters.AddWithValue("@f", txtadult.Text);
    cmd3.Parameters.AddWithValue("@g", txtchild.Text);
    cmd3.Parameters.AddWithValue("@h", ddlclass.SelectedItem.Text);
    cmd3.Parameters.AddWithValue("@i", txtcontpername.Text);
    cmd3.Parameters.AddWithValue("@j", txtcontmobile.Text);
    cmd3.Parameters.AddWithValue("@k", txtamnttocharge.Text);
    cmd3.Parameters.AddWithValue("@l", txtadvamnt.Text);
    cmd3.Parameters.AddWithValue("@m", txtcmnttrav.Text);
    cmd3.Parameters.AddWithValue("@n", txtcmntagnt.Text);




    conn.Open();
    cmd.ExecuteNonQuery();
     cmd2.ExecuteNonQuery();
    cmd3.ExecuteNonQuery();

    conn.Close();
    string display = "Booking Details is added successfully";
    ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('" + display + "');", true);
于 2013-11-09T17:48:51.043 に答える