จากที่ผมเคยทำนะ ผมให้ User กรอกข้อมูลทั้งหมดหรือบางส่วน ส่งตัวนี้เข้าไปค้นหาแล้วให้แสดงออกมาทาง GridView หลังจากนั้น ถ้าต้องการดูรายละเอียดข้อมูลต่างๆจาก GridView ที่แสดงอยู่นั้น
ก้อให้คลิกเลือกที่ชื่อนั้นๆ คิดว่าคงจะคล้ายๆกันนะ ลืมบอกไปว่าที่ GridView นั้นต้องเลือก Enable Selection ด้วยครับ
code ตรงส่วนนี้จะทำหน้าที่ส่งข้อมูลจาก GridView ไปแสดงต่ออีกทีครับ
protected void gridView_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes["onmouseover"] = "javascript:setMouseOverColor(this);"; //เปลี่ยนสีเมื่อมี Mouse อยู่ในแถวนั้นๆในตาราง
e.Row.Attributes["onmouseout"] = "javascript:setMouseOutColor(this);"; //
e.Row.Attributes["onclick"] = ClientScript.GetPostBackClientHyperlink(this.gridAgtName, "Select$" + e.Row.RowIndex);
}
}
เมื่อคลิกแล้ว ข้อมูลจาก GridView แสดงที่ Textbox แต่ถ้าต้องการแบบอื่นก้อลองดูนะครับ
protected void gridAgtView_SelectedIndexChanged(object sender, EventArgs e)
{
tbAgtName.Text = gridView.SelectedRow.Cells[1].Text;
tbAgtID.Text = gridView.SelectedRow.Cells[2].Text;
}
<script type="text/javascript">
var oldgridSelectedColor;
function setMouseOverColor(element)
{
oldgridSelectedColor = element.style.backgroundColor;
element.style.backgroundColor='yellow';
element.style.cursor='hand';
element.style.textDecoration='underline';
}
function setMouseOutColor(element)
{
element.style.backgroundColor=oldgridSelectedColor;
element.style.textDecoration='none';
}
</script>
ลองดูนะครับ เพราะผมก้อมือใหม่ยู่เหมือนกัน