Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP
Hello sir's,
Please help me..
 
1. how to make a cell in a grid view where i can put integer values.
2. And save all grid view data into a database table..
 
Please help me with c# code & example..
Thank you advance...
Posted 31-Mar-13 20:05pm
Comments
vinodkumarnie at 1-Apr-13 1:26am
   
Wat have you tried so far..?
prodipjsr at 1-Apr-13 2:01am
   
Yes but not get any solution..ca u help me Vinod??
ThePhantomUpvoter at 1-Apr-13 8:44am
   
You need to post the code that you have written the demonstrates your problem and describe what the problem is. We cannot guess what it is that you have done or trying to do.
prodipjsr at 1-Apr-13 9:33am
   
my code is::
=================
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Datacollection.aspx.cs" Inherits="New_NPS.Datacollection" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<div>
<script type="text/javascript">
function isNumberKey(evt) {
var charCode = (evt.which) ? evt.which : event.keyCode
if (charCode > 31 && (charCode < 48 || charCode > 57))
return false;
return true;
}

</script>

 

 

put collection amount


<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Member_ID"
DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
GridLines="None" style="margin-right: 54px" Width="303px">




<asp:BoundField DataField="Member_ID" HeaderText="Member_ID" ReadOnly="True"
SortExpression="Member_ID" />
<asp:BoundField DataField="First_Name" HeaderText="First_Name"
SortExpression="First_Name" ReadOnly="True" />
<asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
SortExpression="Last_Name" ReadOnly="True" />

 
<asp:templatefield headertext="Collection Amount">

<asp:textbox id="TextBox1" onkeypress="return isNumberKey(event)" type="Text" runat="server">






<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />





<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:MemberConnectionString %>"

SelectCommand="SELECT [Member_Info].[Member_ID], [Member_Info].[First_Name], [Member_Info].[Last_Name] FROM [Member_Info] inner join [Membermaster] on [Member_Info].[Member_ID]=[Membermaster].[Member_ID]">



<asp:Button ID="btsave" runat="server" onclick="btsave_Click" Text="Save" />



</div>
 



 

====================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
 
namespace New_NPS
{
public partial class Datacollection : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
 
}
 
protected void btsave_Click(object sender, EventArgs e)
{
 
string Member_ID = string.Empty;
//string Frist_Name = string.Empty;
//string Last_Name = string.Empty;
string TextB
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

my code is::
=================
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Datacollection.aspx.cs" Inherits="New_NPS.Datacollection" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <div>
     <script type="text/javascript">
      function isNumberKey(evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57))
                return false;
            return true;
        }
 
   </script>
 

 

    <h1> put collection amount</h1>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True"
            AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="Member_ID"
            DataSourceID="SqlDataSource1" CellPadding="4" ForeColor="#333333"
            GridLines="None" style="margin-right: 54px" Width="303px">
 
                <AlternatingRowStyle BackColor="White" />
 
                <Columns>
                <asp:BoundField DataField="Member_ID" HeaderText="Member_ID" ReadOnly="True"
                        SortExpression="Member_ID" />
                    <asp:BoundField DataField="First_Name" HeaderText="First_Name"
                        SortExpression="First_Name" ReadOnly="True" />
                    <asp:BoundField DataField="Last_Name" HeaderText="Last_Name"
                        SortExpression="Last_Name" ReadOnly="True" />
 

                    <asp:templatefield headertext="Collection Amount">
                    <itemtemplate>
                    <asp:textbox id="TextBox1" onkeypress="return isNumberKey(event)" type="Text" runat="server"></asp:textbox>
                    </itemtemplate>
                    </asp:templatefield>
 
                        </Columns>
                <EditRowStyle BackColor="#2461BF" />
                <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                <RowStyle BackColor="#EFF3FB" />
                <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                <SortedAscendingCellStyle BackColor="#F5F7FB" />
                <SortedAscendingHeaderStyle BackColor="#6D95E1" />
                <SortedDescendingCellStyle BackColor="#E9EBEF" />
                <SortedDescendingHeaderStyle BackColor="#4870BE" />
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server"
                ConnectionString="<%$ ConnectionStrings:MemberConnectionString %>"
 
            SelectCommand="SELECT [Member_Info].[Member_ID], [Member_Info].[First_Name], [Member_Info].[Last_Name] FROM [Member_Info] inner join [Membermaster] on [Member_Info].[Member_ID]=[Membermaster].[Member_ID]"></asp:SqlDataSource>
 

 
          <asp:Button ID="btsave" runat="server" onclick="btsave_Click" Text="Save" />
 

 
          </div>
 

 
</asp:Content>
 

====================
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
 
namespace New_NPS
{
    public partial class Datacollection : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
 
        }
 
        protected void btsave_Click(object sender, EventArgs e)
        {
 
            string Member_ID = string.Empty;
            //string Frist_Name = string.Empty;
            //string Last_Name = string.Empty;
            string TextBox1 = string.Empty;
 

 
            int GVCount = GridView1.Rows.Count;
 
            foreach (GridViewRow GVRow in GridView1.Rows)
            {
                Member_ID = GVRow.Cells[0].Text;
               // Frist_Name = GVRow.Cells[1].Text;
                //Last_Name = GVRow.Cells[2].Text;
                TextBox1 = GVRow.Cells[3].Text;
            }
 
                SqlConnection myConnection = new SqlConnection("user id=sa;" +
                                           "password=prodip@km;server=PRODIP;" +
                                           "Trusted_Connection=yes;" +
                                           "database=Member;");
                myConnection.Open();
 
                SqlCommand myCommand = new SqlCommand("INSERT INTO [Collectionamt ] (Member_ID,collectionamt,collectiondate)" +
    "Values(@Member_ID,@TextBox1,GETDATE())");
 
                //int Member_ID = int.Parse(GVRow.Cells[1].Text);
 

                myCommand.Parameters.Add("@Member_ID", System.Data.SqlDbType.Int).Value = Convert.ToInt32(Member_ID);
                myCommand.Parameters.Add("@TextBox1", System.Data.SqlDbType.Int).Value = Convert.ToInt32(TextBox1);
 

                myCommand.Connection = myConnection;
                myCommand.ExecuteNonQuery();
 
                Response.Write("<script language="'javascript'">{alert('" + "Data is Save')}</script>");
 
                myConnection.Close();
 
        }
    }
}
 

Problem:
1. when i save it then show ''Input string was not in a correct format.''
2. how i save all values in a datagridview???
  Permalink  
Comments
ThePhantomUpvoter at 1-Apr-13 10:47am
   
1. This is not a solution to your problem.
2. You should use the Improve Question widget to actually improve your question.
3. Your question title and narrative have nothing to do with the error you are getting.
4. The error is self explanatory is it not? You are trying to convert a string to an integer that cannot be converted.
5. re #2... just like you are?
prodipjsr at 2-Apr-13 0:57am
   
so how i insert data into database from a text box???
Sergey Alexandrovich Kryukov at 6-May-13 2:10am
   
Not an answer, should be removed.
—SA
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

so how i insert data into database from a text box???
  Permalink  
Comments
Sergey Alexandrovich Kryukov at 6-May-13 2:10am
   
Not an answer, should be removed.
—SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 609
1 OriginalGriff 587
2 Maciej Los 325
3 Mathew Soji 195
4 BillWoodruff 190
0 OriginalGriff 7,356
1 Sergey Alexandrovich Kryukov 6,712
2 DamithSL 5,461
3 Manas Bhardwaj 4,916
4 Maciej Los 4,475


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 2 Apr 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100