i want to store into a store procedure where a hyperlink from the gridview ir datalist can also function as a save button.

the problem is that the list is from the database aswell. and there is a parameter from the table that i do not know how to pass.

Dani AI

Generated

Short answer for : an ASP.NET HyperLink is just for client navigation and will not execute server code. Use a server-side control such as LinkButton or Button inside a TemplateField (or use DataList with ItemCommand) and pass the row key either with CommandArgument='<%# Eval("Id") %>' or via DataKeyNames. Handle RowCommand (or ItemCommand) on the server, detect CommandName == "Save", retrieve the id, then call your stored procedure with a parameterized SqlCommand (CommandType = CommandType.StoredProcedure). This keeps data safe and avoids fragile query strings.

Example patterns (markup + handler):

<asp:GridView ID="gv" runat="server" DataKeyNames="Id" OnRowCommand="gv_RowCommand">
  <Columns>
    <asp:TemplateField>
      <ItemTemplate>
        <asp:LinkButton ID="lnkSave" runat="server"
          CommandName="Save"
          CommandArgument='<%# Eval("Id") %>'
          Text="Save" />
      </ItemTemplate>
    </asp:TemplateField>
  </Columns>
</asp:GridView>
protected void gv_RowCommand(object sender, GridViewCommandEventArgs e)
{
  if (e.CommandName == "Save")
  {
    int id = Convert.ToInt32(e.CommandArgument);
    // Call stored procedure using SqlCommand.CommandType = CommandType.StoredProcedure
  }
}

For (checkboxes): add a TemplateField with a CheckBox and include the primary key in DataKeyNames. On a single "Save Selected" button click iterate GridView.Rows, FindControl("chkSelect"), check .Checked, and pull the id from gv.DataKeys[row.RowIndex].Value. For many rows, batch updates are faster — either pass a DataTable as a table-valued parameter (SQL Server TVP) or send XML and parse server-side. Always use parameterized stored procedures and using blocks for connections/commands.

Recommended Answers

All 2 Replies

What?
I didn't understand what you want,
Please try to explain again and give example of your code\gridview

how to send the gridview checkbox selected data into sqldatabase

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.