Updates of DetailsView and updates of DetailsView in the GridView operation protected void detailsviewincluitemupdating (object sender, DetailsViewUpdateEventArgs e)
Updates of detailsview and updates of detailsview in the gridview operation protected void detailsviewincluitemupdating (object sender,
Detailsviewupdateeventargs e)
{
String tableid = url;
String tablename = tbname;
String m_monthcount;
String m_messagecount;
String m_remark;
String sqlupdate; textbox tb;
Tb = (textbox) (detailsview1.rows [1]. findcontrol ("textbox2 "));
M_monthcount = tb. text; tb = (textbox) (detailsview1.rows [2]. findcontrol ("textbox3 "));
M_messagecount = tb. text; tb = (textbox) (detailsview1.rows [3]. findcontrol ("textbox4 "));
M_remark = tb. text; sqlupdate = "update" + tablename + "set m_monthcount = '" + m_monthcount + "', m_messagecount = '" + m_messagecount + "', m_remark = '"+ m_remark +" 'where m_id =' "+ tableid +" '"; sqlconnection con = db. createsqlcon ();
Con. open ();
Sqlcommand cmd = new sqlcommand (sqlupdate, con );
Cmd.exe cutenonquery ();
Con. close (); //////////////////////////////////////// set the default mode of detailsview to edit ///////////////////////////////// ////////////////// <asp Tutorial: detailsview id = "detailsview1" runat = "server" height = "55px" width = "370px" autogeneraterows = "false" cellpadding = "4" forecolor = "#333333" gridlines =" none "onitemupdating =" detailsviewincluitemupdating "defaultmode =" edit ">
<Fields>
<Asp: templatefield headertext = "company name"> <edititemtemplate>
<Asp: textbox id = "textbox1" runat = "server" width = "200px" readonly = "true" text = '<% # bind ("m_name ") %> '> </asp: textbox>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "Total">
<Edititemtemplate>
<Asp: textbox id = "textbox2" runat = "server" width = "200px" text = '<% # bind ("m_monthcount") %>'> </asp: textbox>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "currently sent">
<Edititemtemplate>
<Asp: textbox id = "textbox3" width = "200px" runat = "server" text = '<% # bind ("m_messagecount") %>'> </asp: textbox>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "Remarks"> <edititemtemplate>
<Asp: textbox id = "textbox4" runat = "server" height = "121px" text = '<% # bind ("m_remark") %>'
Textmode = "multiline" width = "200px"> </asp: textbox>
</Edititemtemplate>
</Asp: templatefield>
<Asp: buttonfield buttontype = "button" commandname = "update" text = "button">
<Headerstyle horizontalalign = "center"/>
</Asp: buttonfield>
</Fields>
<Footerstyle backcolor = "#507cd1" font-bold = "true" forecolor = "white"/>
<Commandrowstyle backcolor = "# d1ddf1" font-bold = "true"/>
<Editrowstyle backcolor = "# 2461bf"/>
<Rowstyle backcolor = "# eff3fb"/>
<Pagerstyle backcolor = "# 2461bf" forecolor = "white" horizontalalign = "center"/>
<Fieldheaderstyle backcolor = "# dee8f5" font-bold = "true"/>
<Headerstyle backcolor = "#507cd1" font-bold = "true" forecolor = "white"/>
<Alternatingrowstyle backcolor = "white"/>
</Asp: detailsview> ////////////////////////////////////// //// // The operation of the gridview /////////////////////////// //////////////////////////////////////// //// **************************/protected void gridview#rowcancelingedit (object sender, gridviewcancelediteventargs e)
{
Gridview1.editindex =-1;
Datagridviewbind1 ();
****************** *****/
Protected void gridviewinclurowediting (object sender, gridviewediteventargs e)
{
Gridview1.editindex = e. neweditindex;
Datagridviewbind1 ();
}/********************** Update operations *************** ***************/
Protected void gridview1_rowupdating (object sender, gridviewupdateeventargs e)
{
String updatacmd = "update" + sqldatatime + "set m_monthcount = '"
+ (Textbox) (gridview1.rows [e. rowindex]. cells [1]. controls [0]). text. tostring (). trim () + "', m_messagecount = '"
+ (Textbox) (gridview1.rows [e. rowindex]. cells [2]. controls [0]). text. tostring (). trim () + "', m_remark = '"
+ (Textbox) (gridview1.rows [e. rowindex]. cells [3]. controls [0]). text. tostring (). trim () + "'where m_id = '"
+ Gridview1.datakeys [e. rowindex]. value. tostring () + "'";
Sqlconnection con = db. createsqlcon ();
Sqlcommand cmd = new sqlcommand (updatacmd, con); con. open ();
Cmd.exe cutenonquery ();
Gridview1.editindex =-1;
Datagridviewbind1 ();
Con. close ();
}
The following describes how to use detailsview in the asp.net tutorial.
<Asp: detailsview id = "detailsview1" runat = "server" autogeneraterows = "false" height = "50px"
Width = "500px" onmodechanging = "detailsview1_modechanging" onitemdeleting = "detailsview1_itemdeleting"
Onitemupdating = "detailsview1_itemupdating" oniteminserting = "detailsview1_iteminserting">
<Fields>
<Asp: templatefield headertext = "id">
<Itemtemplate>
<% # Eval ("id") %>
</Itemtemplate>
<Insertitemtemplate>
<Asp: textbox id = "txtinsertid" text = "insertid" runat = "server"/>
</Insertitemtemplate>
<Edititemtemplate>
<% # Eval ("id") %>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "title">
<Itemtemplate>
<% # Eval ("title") %>
</Itemtemplate>
<Insertitemtemplate>
<Asp: textbox id = "txtinserttitle" text = "inserttitle" runat = "server"/>
</Insertitemtemplate>
<Edititemtemplate>
<Asp: textbox id = "txtedittitle" text = '<% # eval ("title") %> 'runat = "server"/>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "context">
<Itemtemplate>
<% # Eval ("logcontext") %>
</Itemtemplate>
<Insertitemtemplate>
<Asp: textbox id = "txtinsertlogcontext" text = "insertlogcontext" runat = "server"/>
</Insertitemtemplate>
<Edititemtemplate>
<Asp: textbox id = "txteditlogcontext" text = '<% # eval ("logcontext") %> 'runat = "server"/>
</Edititemtemplate>
</Asp: templatefield>
<Asp: templatefield headertext = "operation">
<Itemtemplate>
<Asp: button id = "btnedit" runat = "server" causesvalidation = "false"
Commandname = "edit" text = "edit"/>
<Asp: button id = "btnnew" runat = "server" causesvalidation = "false"
Commandname = "new" text = "new"/>
<Asp: button id = "btndelete" runat = "server" causesvalidation = "false"
Commandname = "delete" text = "delete" onclientclick = "return confirm ('Are you sure you want to update this student information? '); "/>
</Itemtemplate>
<Insertitemtemplate>
<Asp: button id = "btninsert" runat = "server" causesvalidation = "true"
Commandname = "insert" text = "insert"/>
<Asp: button id = "btncancel" runat = "server" causesvalidation = "false"
Commandname = "cancel" text = "cancel"/>
</Insertitemtemplate>
<Edititemtemplate>
<Asp: button id = "btnupdate" runat = "server" causesvalidation = "true"
Commandname = "update" text = "update" onclientclick = "return confirm ('Are you sure you want to update this student information? '); "/>
<Asp: button id = "btncancel2" runat = "server" causesvalidation = "false"
Commandname = "cancel" text = "cancel"/>
</Edititemtemplate>
</Asp: templatefield>
</Fields>
</Asp: detailsview>