1 / 8

การ ใช้งาน GridView FormView การแสดงรูปภาพ

การ ใช้งาน GridView FormView การแสดงรูปภาพ. การแสดงรูปภาพผ่าน FormView. สร้าง datasource ติดต่อกับตาราง UserPic เพื่อเลือก username และ รูปภาพขึ้นมาแสดงผล โดยให้ค่าพารามิเตอร์ username มาจาก Session " SELECT * FROM [ UserPic ] WHERE ([username] = @username )”

ewa
Download Presentation

การ ใช้งาน GridView FormView การแสดงรูปภาพ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. การใช้งานGridViewFormViewการแสดงรูปภาพการใช้งานGridViewFormViewการแสดงรูปภาพ

  2. การแสดงรูปภาพผ่าน FormView • สร้างdatasource ติดต่อกับตารางUserPicเพื่อเลือก username และรูปภาพขึ้นมาแสดงผล โดยให้ค่าพารามิเตอร์ username มาจาก Session "SELECT * FROM [UserPic] WHERE ([username] = @username)” • สร้างFormViewแล้วจับคู่กับ datasourceข้างต้น • สร้าง <asp:Image> ภายในFormViewโดย Edit DataBindingsดังรูป

  3. สร้างตารางเพิ่มเติม • สร้างตารางโดยไปที่ Database explorer> table > add new table • กำหนดให้สร้างตารางStudentเก็บข้อมูลนักศึกษา

  4. สร้างหน้า Student.aspx • สร้างDataSourceติดต่อกับตาราง Student โดยใช้คำสั่ง select * from student • กำหนดให้DataSourceสามารถเพิ่มคำสั่ง insert/update/delete ได้

  5. หน้า Student.aspx • สร้างFormView เพื่อใช้แสดงผลข้อมูล Student • สามารถเข้าไปแก้ไข template ได้ที่ Edit Template

  6. protectedvoidexeSQL(stringins_cmd) { try{ SqlCommandinsert_cmd=newSqlCommand(ins_cmd, dbcon.conn); insert_cmd.ExecuteNonQuery(); lbStatus.Text="เพิ่มข้อมูลสำเร็จ"; } catch (SqlExceptionse) { lbStatus.Text="เพิ่มข้อมูลไม่สำเร็จ "+se.ToString(); } }

  7. protectedvoidButton1_Click(objectsender, EventArgse) { boolisPay; doublemid,final; chargrade; stringins_cmd; connect_db(); foreach (GridViewRowgvrinGridView1.Rows) { isPay= ((CheckBox)(gvr.FindControl("cbPay"))).Checked; if (isPay==true) { mid=Convert.ToDouble(((TextBox)(gvr.FindControl("tbMid"))).Text); final=Convert.ToDouble(((TextBox)(gvr.FindControl("tbFinal"))).Text); grade='A'; ins_cmd=“ เขียนคำสั่ง update………"; ins_cmd+=" where studentID='"+gvr.Cells[0].Text+"'"; exeSQL(ins_cmd); } } dbcon.closeDB(); GridView1.DataBind(); } protectedvoidconnect_db() {

  8. protectedvoidGridView1_RowDataBound(objectsender, GridViewRowEventArgse) { charx; if (e.Row.RowType==DataControlRowType.DataRow) { x=Convert.ToChar( DataBinder.Eval(e.Row.DataItem, "grade")); if (x=='F') { e.Row.BackColor=System.Drawing.Color.Red; } } }

More Related