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

    Want to track updated by and updated id when grid record is changed

    I have a requirement where if any change is made to a row in text box and drop down list values , for every row there is a Button click, when the row is changed by some one..changes must be saved along with "UpdatedBy" and "UpdatedId" , must be saved in grid view and database too..

    How to write the logic in frontend to handle this?
  • #765943
    every child control fire its row command event you can check it in griview, as per your description you have Textbox and dropdownlist right ?
    you can Fire TextChanged event for GridView inside TextBox in ASP.Net
    see below snippet

    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false">
    <Columns>
    <asp:BoundField DataField="Name" HeaderText="Name" />
    <asp:BoundField DataField="Country" HeaderText="Country" />
    <asp:TemplateField>
    <ItemTemplate>
    <asp:TextBox runat="server" OnTextChanged = "OnTextChanged" AutoPostBack = "true" />
    </ItemTemplate>
    </asp:TemplateField>
    </Columns>
    </asp:GridView>

    //in CS file
    protected void Page_Load(object sender, EventArgs e)
    {
    if (!this.IsPostBack)
    {
    DataTable dt = new DataTable();
    dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id", typeof(int)),
    new DataColumn("Name", typeof(string)),
    new DataColumn("Country",typeof(string)) });
    dt.Rows.Add(1, "John Hammond", "United States");
    dt.Rows.Add(2, "Mudassar Khan", "India");
    dt.Rows.Add(3, "Suzanne Mathews", "France");
    dt.Rows.Add(4, "Robert Schidner", "Russia");
    GridView1.DataSource = dt;
    GridView1.DataBind();
    }
    }
    protected void OnTextChanged(object sender, EventArgs e)
    {
    ClientScript.RegisterClientScriptBlock(GetType(), "alert", "alert('" + (sender as TextBox).Text + "');", true);
    }

    hope it helps

    Thanks
    Koolprasd2003
    Editor, DotNetSpider MVM
    Microsoft MVP 2014 [ASP.NET/IIS]

  • #765957
    hi prasad,
    based on login user, when the user changes any record when i click on save button .who ever updated the record and also updated id must have save.

    how to write logic for current user?

  • #765963
    Hello,

    Before answering this question please clarify few things :-

    i) Did you using any separate user table?
    ii) Are you maintaining user id or user in session variable in front-end? the user value or id should stored in session variable so that it can be easily display on GridView as well as stored in DB.
    iii) Lastly, what does updated id referred to? Is it the Auto generated id of the the table that you are currently using for update?

    Thanks

  • #765970
    Hi

    Set Textbox Property Autopostback="True" then right the code for update your db then changed your field
    UpdatedBy etc also

    Create one updated Query or call stored procedure then call your row change event raising call that method.

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

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

  • #765979
    Hi,

    On button click or rowcommand event of gridview do your action, pass the updated date & user details to update the details in database, once it is updated then rebind your grid, so that it will populate the new changes in your gridview.

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

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

  • #765985
    How you are handling the current user?. I hope you may save that user value in "Session". If not save the user name/id in the session.
    In the button click you are saving the data in the database right?. You can check the value and based on that you can get the user details from the session and save that in the database. You can check it in the "Stored Procedure" level or C# code level. All are based on your coding style.

    By Nathan
    Direction is important than speed


  • Sign In to post your comments