Вы можете использовать map
для преобразования столбца, используя словарь для определения преобразования:
price_dict = {91:0, 65:1, 0:1, 20:1, 35:1, 32:1, 41:1, 36:1, 15:1, 90:1, 6:1, 67:1, 2:1, 57:1, 39:1, 1:1, 79:1, 34:1, 85:1} # not all
app['Price'] = app['Price'].map(price_dict)
app['Price'].value_counts()
Вы также можете заменить значения в столбцах следующим образом:
app['Price_new'] = 1
app.loc[app.Price == 91, 'Price_new'] = 0
Некоторое программирование JavaScript будет требоваться, чтобы заставить это произойти.
В основном Вы оказываетесь перед необходимостью обрабатывать событие щелчка для строки (некоторые браузеры, строка не имеет события щелчка, таким образом, Вам, возможно, придется обработать событие щелчка tds... время для инвестирования в ajax платформу!)
Вы будете затем из JavaScript, должны запустить обратную передачу с индексом строки в качестве параметра. См. encosia (большой сайт для ASP.NET - ajax реализации) о том, как сделать это. Вот ссылка на статью вдоль тех строк
Вот что-то, что я подготовил ранее:
public class RowClickableGridView : GridView
{
public Style HoverRowStyle
{
get { return ViewState["HoverRowStyle"] as Style; }
set { ViewState["HoverRowStyle"] = value; }
}
public bool EnableRowClickSelection
{
get { return ViewState["EnableRowClickSelection"] as bool? ?? true; }
set { ViewState["EnableRowClickSelection"] = value; }
}
public string RowClickCommand
{
get { return ViewState["RowClickCommand"] as string ?? "Select"; }
set { ViewState["RowClickCommand"] = value; }
}
public string RowToolTip
{
get
{
if (!RowToolTipSet) return string.Format("Click to {0} row", RowClickCommand.ToLowerInvariant());
return ViewState["RowToolTip"] as string;
}
set
{
ViewState["RowToolTip"] = value;
RowToolTipSet = true;
}
}
private bool RowToolTipSet
{
get { return ViewState["RowToolTipSet"] as bool? ?? false; }
set { ViewState["RowToolTipSet"] = value; }
}
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
foreach (GridViewRow row in Rows)
{
if (row.RowType != DataControlRowType.DataRow) continue;
if (EnableRowClickSelection && row.RowIndex != SelectedIndex && row.RowIndex != EditIndex)
{
if (string.IsNullOrEmpty(row.ToolTip)) row.ToolTip = RowToolTip;
row.Style[HtmlTextWriterStyle.Cursor] = "pointer";
PostBackOptions postBackOptions = new PostBackOptions(this,
string.Format("{0}${1}",
RowClickCommand,
row.RowIndex));
postBackOptions.PerformValidation = true;
row.Attributes["onclick"] = Page.ClientScript.GetPostBackEventReference(postBackOptions);
foreach (TableCell cell in row.Cells)
{
foreach (Control control in cell.Controls)
{
const string clientClick = "event.cancelBubble = true;{0}";
WebControl webControl = control as WebControl;
if (webControl == null) continue;
webControl.Style[HtmlTextWriterStyle.Cursor] = "Auto";
Button button = webControl as Button;
if (button != null)
{
button.OnClientClick = string.Format(clientClick, button.OnClientClick);
continue;
}
ImageButton imageButton = webControl as ImageButton;
if (imageButton != null)
{
imageButton.OnClientClick = string.Format(clientClick, imageButton.OnClientClick);
continue;
}
LinkButton linkButton = webControl as LinkButton;
if (linkButton != null)
{
linkButton.OnClientClick = string.Format(clientClick, linkButton.OnClientClick);
continue;
}
webControl.Attributes["onclick"] = string.Format(clientClick, string.Empty);
}
}
}
if (HoverRowStyle == null) continue;
if (row.RowIndex != SelectedIndex && row.RowIndex != EditIndex)
{
row.Attributes["onmouseover"] = string.Format("this.className='{0}';", HoverRowStyle.CssClass);
row.Attributes["onmouseout"] = string.Format("this.className='{0}';",
row.RowIndex%2 == 0
? RowStyle.CssClass
: AlternatingRowStyle.CssClass);
}
else
{
row.Attributes.Remove("onmouseover");
row.Attributes.Remove("onmouseout");
}
}
}
protected override void Render(HtmlTextWriter writer)
{
base.Render(writer);
foreach (GridViewRow row in Rows)
{
if (row.RowType == DataControlRowType.DataRow)
{
Page.ClientScript.RegisterForEventValidation(row.ClientID);
}
}
}
}
Вы затем сцепляетесь в стандартные события команды строки...
Нет никакого существующего события для обработки всего щелчка строки. Ваш лучший выбор состоит в том, чтобы иметь некоторый JavaScript (возможно, через Ajax ASP.NET), обнаруживают щелчок и запускают событие самостоятельно. Кроме того, необходимо было бы создать кнопку или флажок, который устанавливает пользователь.
Необходимо обработать событие "SelectedIndexChanged", можно затем запросить сетку для.SelectedRow. Alternativley используют событие "SelectedIndexChanging", которое устанавливает "e. NewSelectedIndex"
Проверьте эту статью Teemu, в том, где он объясняет о нажатии на строку в Gridview, и бросьте событие RowClicked.
Вот выборка кода:
Protected Overrides Sub RaisePostBackEvent(ByVal eventArgument As String)
If eventArgument.StartsWith("rc") Then
Dim index As Integer = Int32.Parse(eventArgument.Substring(2))
Dim args As New GridViewRowClickedEventArgs(Me.Rows(index))
OnRowClicked(args)
Else
MyBase.RaisePostBackEvent(eventArgument)
End If
End Sub
Public Class GridViewRowClickedEventArgs
Inherits EventArgs
Private _row As GridViewRow
Public Sub New(ByVal row As GridViewRow)
_row = row
End Sub
Public ReadOnly Property Row() As GridViewRow
Get
Return _row
End Get
End Property
End Class
Btw, это находится в VB не C# все же.