单击 某行 改变gridview色彩
单击 某行 改变gridview颜色
我想实现单击 某行 改变gridview这行的颜色 ,鼠标悬停和经过的已经改好了,但是鼠标click事件的颜色绑定不成功。总是显示鼠标经过的颜色。
cs
protected void gwDataList_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button btnHiddenPostButton = e.Row.FindControl("btnHiddenPostButton") as Button;
if (btnHiddenPostButton != null)
{
e.Row.Attributes["onclick"] = String.Format("javascript:document.getElementById('{0}').click()", btnHiddenPostButton.ClientID);
e.Row.Attributes.Add("onmouseover", "this.style.background='red'");
e.Row.Attributes.Add("onmouseout", "this.style.background='white'");
}
}
protected void changegwDataListColor(object sender, EventArgs e)
{
if (tRowID.Text != "")
{
gwDataList.Rows[int.Parse(tRowID.Text)].BackColor = System.Drawing.Color.Red;
}
}
protected void gwDataList_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = null;
if (e.CommandName == "HiddenPostButtonCommand")
{
Control cmdControl = e.CommandSource as Control;
row = cmdControl.NamingContainer as GridViewRow;
gwChatList.EditIndex = -1;
getDetail(row.Cells[0].Text, row.Cells[2].Text);
//測定情報の測定ID
tID.Text = row.Cells[0].Text;
//測定情報の測定種別
tCV.Text = row.Cells[2].Text;
tRowID.Text = e.CommandArgument.ToString();
gwDataList.Rows[int.Parse(tRowID.Text)].BackColor = System.Drawing.Color.Orange;
}
asp
<asp:GridView ID="gwDataList" runat="server" AutoGenerateColumns="False"
Width="1060px" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" OnRowDataBound="gwDataList_RowDataBound" OnRowCommand="gwDataList_RowCommand">
<AlternatingRowStyle />
<Columns>
<asp:BoundField DataField="measurement_id" HeaderText="測定ID" >
<ItemStyle Width="60px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="測定日時" DataField="measurement_time" ItemStyle-Width="150px"
NullDisplayText="-">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="測定種別" DataField="inspection_type" ItemStyle-Width="100px"
NullDisplayText="-">
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="神経種別" DataField="nerve_name" ItemStyle-Width="90px" NullDisplayText="-">
我想实现单击 某行 改变gridview这行的颜色 ,鼠标悬停和经过的已经改好了,但是鼠标click事件的颜色绑定不成功。总是显示鼠标经过的颜色。
cs
protected void gwDataList_RowDataBound(object sender, GridViewRowEventArgs e)
{
Button btnHiddenPostButton = e.Row.FindControl("btnHiddenPostButton") as Button;
if (btnHiddenPostButton != null)
{
e.Row.Attributes["onclick"] = String.Format("javascript:document.getElementById('{0}').click()", btnHiddenPostButton.ClientID);
e.Row.Attributes.Add("onmouseover", "this.style.background='red'");
e.Row.Attributes.Add("onmouseout", "this.style.background='white'");
}
}
protected void changegwDataListColor(object sender, EventArgs e)
{
if (tRowID.Text != "")
{
gwDataList.Rows[int.Parse(tRowID.Text)].BackColor = System.Drawing.Color.Red;
}
}
protected void gwDataList_RowCommand(object sender, GridViewCommandEventArgs e)
{
GridViewRow row = null;
if (e.CommandName == "HiddenPostButtonCommand")
{
Control cmdControl = e.CommandSource as Control;
row = cmdControl.NamingContainer as GridViewRow;
gwChatList.EditIndex = -1;
getDetail(row.Cells[0].Text, row.Cells[2].Text);
//測定情報の測定ID
tID.Text = row.Cells[0].Text;
//測定情報の測定種別
tCV.Text = row.Cells[2].Text;
tRowID.Text = e.CommandArgument.ToString();
gwDataList.Rows[int.Parse(tRowID.Text)].BackColor = System.Drawing.Color.Orange;
}
asp
<asp:GridView ID="gwDataList" runat="server" AutoGenerateColumns="False"
Width="1060px" BorderColor="#999999" BorderStyle="None" BorderWidth="1px" CellPadding="3"
GridLines="Vertical" OnRowDataBound="gwDataList_RowDataBound" OnRowCommand="gwDataList_RowCommand">
<AlternatingRowStyle />
<Columns>
<asp:BoundField DataField="measurement_id" HeaderText="測定ID" >
<ItemStyle Width="60px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="測定日時" DataField="measurement_time" ItemStyle-Width="150px"
NullDisplayText="-">
<ItemStyle Width="150px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="測定種別" DataField="inspection_type" ItemStyle-Width="100px"
NullDisplayText="-">
<ItemStyle Width="80px"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="神経種別" DataField="nerve_name" ItemStyle-Width="90px" NullDisplayText="-">