You must Sign In to post a response.
  • Category: ASP.NET

    In a textbox i give the value and i show the data in the gridview but i cannot show the da

    my need is


    regno name adress
    100 celv kkdi
    101 mani sivagangai
    102 pandi madurai


    in this regno i never give in textbox i give name and adress ..
  • #762314
    Hi selvi.

    Regno column may be you have made it as auto increment number in your database table.

    Remove that auto increment and manually create the column regno.

    Post the part of code which you have tried for displaying in gridview.

    Regards

    Sridhar Thota.

    Sridhar Thota.
    Editor: DNS Forum.

  • #762323
    Hi

    I assume your need this may be try this code

    Client side



    RegNo <asp:TextBox ID="TxtRegno" runat="server"></asp:TextBox>
    Name <asp:TextBox ID="TxtNameEntry" runat="server" OnTextChanged="TxtNameEntry_TextChanged"></asp:TextBox>
    Address <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>

    <asp:GridView ID="Grd1" runat="server">
    </asp:GridView>



    Server side c# code


    protected void TxtNameEntry_TextChanged(object sender, EventArgs e)
    {
    DataTable dt = new DataTable();
    // If you need all fields means use this
    //SqlDataAdapter sqladp = new SqlDataAdapter("Select * from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);

    // If you need Particular fields means use this
    SqlDataAdapter sqladp = new SqlDataAdapter("Select regno from tblEmplist where name like '%" + TxtNameEntry.Text + "%'", con);
    sqladp.Fill(dt);
    Grd1.DataSource=dt;
    Grd1.DataBind();

    }


    Table Records this



    Create Table tblEmplist
    (
    regno int,
    name varchar(40),
    adress varchar(30)
    )

    Insert into tblEmplist values(100,'John','Chennai')
    Insert into tblEmplist values(101,'Joshva','Coimbatore')
    Insert into tblEmplist values(102,'JK','Madurai')



    Select * from tblEmplist where name like '%john%'
    Select * from tblEmplist where name like '%john'
    Select * from tblEmplist where name like 'john%'



    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

  • #762324
    Hi

    I have attached Image give below.

    If my answer not suitable in your issue means post again.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762329
    Hi selvi,

    Your question is not clear, could you please elaborate your requirement so that we can help you better.

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/

  • #762373
    Hi

    I assume your output this may be try and let me know
    for add records Dynamically.

    Client Side Html Code


    <form id="form1" runat="server">
    RegNo <asp:TextBox ID="TxtRegno" runat="server"></asp:TextBox>
    Name <asp:TextBox ID="TxtNameEntry" runat="server" OnTextChanged="TxtNameEntry_TextChanged" AutoPostBack="true"></asp:TextBox>
    Address <asp:TextBox ID="TxtAddress" runat="server"></asp:TextBox>

    <asp:GridView ID="Grd1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="regno" HeaderText="Regno" />
    <asp:BoundField DataField="name" HeaderText="Name" />
    <asp:BoundField DataField="Address" HeaderText="Address" />
    </Columns>
    </asp:GridView>

    <asp:Button ID="bt1" runat="server" Text="Word" OnClick="bt1_Click" />
    </form>




    Server Side C# Code


    protected void TxtNameEntry_TextChanged(object sender, EventArgs e)
    {


    if (ViewState["Dtdata1"] == null)
    {
    dt = new DataTable("Dtdata1");
    dt.Columns.Add("RegNo", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Address", typeof(string));
    }
    else
    {
    dt = (DataTable)ViewState["Dtdata1"];
    }

    DataRow dt_row;
    dt_row = dt.NewRow();
    dt_row["RegNo"] = 1000 + dt.Rows.Count + 1;
    dt_row["Name"] = TxtNameEntry.Text;
    dt_row["Address"] = TxtAddress.Text;
    dt.Rows.Add(dt_row);
    ViewState["Dtdata1"] = dt;
    Grd1.DataSource = dt;
    Grd1.DataBind();
    }


    I have attached Snapshots given below.

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment

  • #762397
    have to fetch the last record and compare the value if the last value is 101 i need to put the record as 102

  • #762402
    Hi

    You can try this code for Order No



    protected void TxtNameEntry_TextChanged(object sender, EventArgs e)
    {

    if (Grd1.Rows.Count > 0)
    {
    GridViewRow row = Grd1.Rows[Grd1.Rows.Count - 1];

    DataTable dt = new DataTable("Dtdata1");
    dt.Columns.Add("RegNo", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Address", typeof(string));

    dt = (DataTable)ViewState["Dtdata1"];
    DataRow dt_row;
    dt_row = dt.NewRow();
    dt_row["RegNo"] = Convert.ToInt32(row.Cells[0].Text)+1;
    dt_row["Name"] = TxtNameEntry.Text;
    dt_row["Address"] = TxtAddress.Text;
    dt.Rows.Add(dt_row);
    Grd1.DataSource = dt;
    Grd1.DataBind();
    }
    else
    {
    DataTable dt1 = new DataTable();
    SqlDataAdapter sqladp = new SqlDataAdapter("Select top 1 RegNo + 1 as RegNo from tblEmplist order by Regno desc", con);
    sqladp.Fill(dt1);


    DataTable dt = new DataTable("Dtdata1");
    dt.Columns.Add("RegNo", typeof(int));
    dt.Columns.Add("Name", typeof(string));
    dt.Columns.Add("Address", typeof(string));

    DataRow dt_row;
    dt_row = dt.NewRow();
    dt_row["RegNo"] = Convert.ToInt32(dt1.DefaultView[0]["RegNo"]);
    dt_row["Name"] = TxtNameEntry.Text;
    dt_row["Address"] = TxtAddress.Text;
    dt.Rows.Add(dt_row);

    Grd1.DataSource = dt;
    Grd1.DataBind();
    ViewState["Dtdata1"] = dt;
    }



    I have attached image given below

    Name : Dotnet Developer-2015
    Email Id :kumaraspcode2009@gmail.com

    'Not by might nor by power, but by my Spirit,' says the LORD Almighty.

    Delete Attachment


Sign In to post your comments