I have a gridview , I want one invisible column to be a product of two other visible columns, at the time of updating. What is the best way to do it.
Thanks
Use the datakeynames property e.g. I assume that you use ProductID (or whatever the name of your column is) to update the selected row/productVB.NET
Protected Sub GridView1_RowUpdating(sender As Object, e As GridViewUpdateEventArgs) Handles GridView1.RowUpdating
Dim ProductID As Integer = Convert.ToInt32(GridView1.SelectedDataKey.Value)
' keep updating the row
End Sub
C#
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int ProductID = Convert.ToInt32(GridView1.SelectedDataKey.Value);
// keep updating the row
}
You can use the Datakeynames you achive your task
refer
http://stackoverflow.com/questions/7808104/asp-net-getting-datakey-from-gridview-on-edit-and-delete
Without any Doubt Use DataKeyNames...Something in these lines....
SkinID="GridView1" runat="server" AutoGenerateColumns="false" OnRowCommand="ShowInformation" OnRowDataBound="grdSearchResults_OnRowDataBound"
Width="90%">
and then you can access those values like
grdSearchResults.DataKeys[e.Row.RowIndex]["Active"] or grdSearchResults.DataKeys[e.Row.RowIndex]["Website"]
Register the update event of data grid, get both of the visible columns and just multiply their values. Thanks
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
var resultValue = GridView1.selectedRow["visible1"]*GridView1.selectedRow["visible2"];
}
沒有留言:
張貼留言