Gridview模板中編輯的操作

2021-09-06 02:30:14 字數 3507 閱讀 9257

在gridview模板中編輯的操作,在正常的現實狀態下,應該使用的是:模板(非編輯狀態),在啟動編輯狀態時候,使用 

,前台**如下:

1

<

asp:gridview id="

gridview1

"runat="

server

"autogeneratecolumns="

false"2

onrowcancelingedit="

gridview1_rowcancelingedit"3

onrowediting="

gridview1_rowediting

"onrowupdating="

gridview1_rowupdating

">

4<

columns

>

5<

asp:templatefield headertext="

customerid

">

6<

itemtemplate

>

7#eval(

"customerid")

%>

8itemtemplate

>

9<

edititemtemplate

>

10#eval(

"customerid")

%>

11edititemtemplate

>

12asp:templatefield

>

13<

asp:templatefield headertext="

companyname

">

14<

itemtemplate

>

15#eval(

"companyname")

%>

16itemtemplate

>

17<

edititemtemplate

>

18<

asp:textbox id="

textbox1

"text ='

'runat="

server

">

asp:textbox

>

19edititemtemplate

>

20asp:templatefield

>

21<

asp:templatefield headertext="

contactname

">

22<

itemtemplate

>

23#eval(

"contactname")

%>

24itemtemplate

>

25<

edititemtemplate

>

26<

asp:textbox id="

textbox2

"runat="

server

"text ='

'>

asp:textbox

>

27edititemtemplate

>

28asp:templatefield

>

29<

asp:templatefield headertext="

contacttitle

">

30<

itemtemplate

>

31#eval(

"contacttitle")

%>

32itemtemplate

>

33<

edititemtemplate

>

34#eval(

"contacttitle")

%>

35edititemtemplate

>

36asp:templatefield

>

37<

asp:templatefield headertext="

編輯">

38<

itemtemplate

>

39<

asp:button id="

button1

"runat="

server

"text="

編輯"commandname="

edit

"/>

40itemtemplate

>

41<

edititemtemplate

>

42<

asp:button id="

button2

"runat="

server

"text="

修改"commandname="

update

"/>

43<

asp:button id="

button3

"runat="

server

"text="

取消"commandname="

cancel

"/>

44edititemtemplate

>

45asp:templatefield

>

46columns

>

47asp:gridview

>

後台**:

1

protected

void

page_load(

object

sender, eventargs e)27

}8public

void

databind()9;

19this

.gridview1.databind();20}

21protected

void

gridview1_rowediting(

object

sender, gridviewediteventargs e)

2226

protected

void

gridview1_rowcancelingedit(

object

sender, gridviewcancelediteventargs e)

2731

protected

void

gridview1_rowupdating(

object

sender, gridviewupdateeventargs e)

3252

cmd.executenonquery();

53this

.gridview1.editindex =-

1;54databind();

5556}

GridView的編輯方法

protected void gridview1 rowediting object sender,gridviewediteventargs e protected void gridview1 rowcancelingedit object sender,gridviewcanceleditev...

gridview中cell的選擇和編輯

aspx中定義乙個js函式 其中aspx中form名稱為 myform 新增三個隱藏域 protected void gridview1 rowdatabound object sender,gridviewroweventargs e e.row.rowindex,i 在aspx.cs 中定義gr...

gridview 中編輯狀態為下拉列表控制項

1 在編輯模板中新增控制項 eval typename 2 在.cs 檔案中 protected void gvimages rowdatabound object sender,gridviewroweventargs e if dropdownlist e.row.findcontrol ddl...