<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
CellPadding="4" ForeColor="#333333" GridLines="None"
DataKeyNames="tradecode"
onselectedindexchanging="GridView1_SelectedIndexChanging" OnRowDataBound="GridView1_RowDataBound"
SkinID="tradecode">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="tradecode" HeaderText="商品编号" />
<asp:BoundField DataField="fullname" HeaderText="商品名称" />
<asp:BoundField DataField="type" HeaderText="商品型号" />
<asp:BoundField DataField="standard" HeaderText="商品规格" />
<asp:BoundField DataField="unit" HeaderText="商品单位" />
<asp:BoundField DataField="produce" HeaderText="商品产地" />
<asp:BoundField DataField="qty" HeaderText="库存数量" />
<asp:BoundField DataField="stockcheck" HeaderText="盘点数量" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
CellPadding="4" ForeColor="#333333" GridLines="None"
DataKeyNames="tradecode"
onselectedindexchanging="GridView1_SelectedIndexChanging" OnRowDataBound="GridView1_RowDataBound"
SkinID="tradecode">
<RowStyle BackColor="#EFF3FB" />
<Columns>
<asp:BoundField DataField="tradecode" HeaderText="商品编号" />
<asp:BoundField DataField="fullname" HeaderText="商品名称" />
<asp:BoundField DataField="type" HeaderText="商品型号" />
<asp:BoundField DataField="standard" HeaderText="商品规格" />
<asp:BoundField DataField="unit" HeaderText="商品单位" />
<asp:BoundField DataField="produce" HeaderText="商品产地" />
<asp:BoundField DataField="qty" HeaderText="库存数量" />
<asp:BoundField DataField="stockcheck" HeaderText="盘点数量" />
</Columns>
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<EditRowStyle BackColor="#2461BF" />
<AlternatingRowStyle BackColor="White" />
</asp:GridView>
{
string tradeCode = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
string fullname = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
Session["name"] = fullname;
this.tBoxStock.Text = tradeCode;
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
int i;
//执行循环,保证每条数据都可以更新
for (i = 0; i < GridView1.Rows.Count; i++)
{
//首先判断是否是数据行
if (e.Row.RowType == DataControlRowType.DataRow)
{
//当鼠标停留时更改背景色
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#00A9FF'");
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
}
protected void GridView1_SelectedIndexChanged(object sender, GridViewSelectEventArgs e)
{
string tradeCode = GridView1.Rows[e.NewSelectedIndex].Cells[0].Text;
string fullname = GridView1.Rows[e.NewSelectedIndex].Cells[1].Text;
Session["name"] = fullname;
this.tBoxStock.Text = tradeCode;
}
应该是你哪里不经意变更了设置。
你可以先拖一个新的GRIDVIEW控件,
自己随意造些数据.再绑定(不指定列名)
试下.应该是可以的.
你再对比原来的控件,看是哪里设置不正常.
<asp:BoundField DataField="tradecode" HeaderText="商品编号" />
<asp:BoundField DataField="fullname" HeaderText="商品名称" />
<asp:BoundField DataField="type" HeaderText="商品型号" />
<asp:BoundField DataField="standard" HeaderText="商品规格" />
<asp:BoundField DataField="unit" HeaderText="商品单位" />
<asp:BoundField DataField="produce" HeaderText="商品产地" />
<asp:BoundField DataField="qty" HeaderText="库存数量" />
<asp:BoundField DataField="stockcheck" HeaderText="盘点数量" />
<asp:ButtonField CommandName="Select" Text="Select" />
</Columns>
//当鼠标移开时还原背景色
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");这样设置的是TR的事件,你可以试下在TD上设置onmouseover 事件
protected void GridView_BulletinList_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
LinkButton lb1 = e.Row.FindControl("LinkButton_Del") as LinkButton; lb1.Attributes.Add("onclick", " return confirm('确定要删除吗?')");
}
}