asp.net中的gridview控件 [英] gridview controls in asp.net
本文介绍了asp.net中的gridview控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何使用后面的代码在gridview中编写更新查询,然后第一列只读,但另一列是可编辑的,然后最后更新程序请帮助我
解决方案
< pre lang =vb>< asp:GridView ID = GVAmountReceived runat = server DataKeyNames = sno EmptyDataText = 找不到记录
Style = margin-bottom:6px BorderColor = #BDBDBD AllowPaging = true PageSize = 20>
< columns>
< asp:templatefield headertext = S.No。 footerstyle-horizontalalign = < span class =code-string> Center itemstyle-horizontalalign = < span class =code-string> Center xmlns:asp = #unknown>
< itemtemplate>
<%#Container.DataItemIndex + 1 %>
< / itemtemplate >
< / asp:templatefield >
< asp:boundfield headertext = 派对名称 datafield = partyname xmlns:asp = #未知跨度>>
ItemStyle-HorizontalAlign = 中心 ReadOnly = true />
< asp:templatefield headertext = 日期 itemstyle-horizontalalign = 中心>
< edititemtemplate>
< asp:textbox runat = server id = txt_date width = 90px> < / asp:textbox >
< asp:calendarextender id = calrecdate runat = server targetcontrolid = txt_date onclientdateselectionchanged = checkDate format = dd / MM / yyyy enabled = True />
< asp:requiredfieldvalidator id = RFVrecdate runat = server controltovalidate = txt_date跨度>>
Display = 无 ErrorMessage = 必须输入日期 ValidationGroup = duereport > < / asp:requiredfieldvalidator >
< asp:validatorcalloutextender id = VCErecdate runat = 服务器 targetcontrolid = < span class =code-string> RFVrecdate />
< / edititemtemplate >
< / asp:templatefield >
< asp:commandfield showsitbutton = true headertext = 编辑 validationgroup = duereport />
< / asp:boundfield > < / 列 >
.cs这样的页面
DataTable dtinsert = new DataTable();
// TextBox txtparty =(TextBox)GVAmountReceived.Rows [e.RowIndex] .Cells [1]。控件[1];
// DropDownList ddlparty =(DropDownList)GVAmountReceived.Rows [e .RowIndex] .Cells [1] .Controls [1];
TextBox txtrecdate =(TextBox)GVAmountReceived.Rows [e.RowIndex] .Cells [ 3 ]。控制[ 1 ];
TextBox txtrecamount =(TextBox)GVAmountReceived.Rows [e.RowIndex] .Cells [ 4 ]。控件[ 1 跨度>];
TextBox txtchknumber =(TextBox)GVAmountReceived.Rows [e.RowIndex] .Cells [ 5 ]。控件[ 1 跨度>];
string partyname = Convert.ToString(GVAmountReceived.DataKeys [e.RowIndex] .Values [ 0 跨度>]的ToString());
IFormatProvider provider = new System.Globalization.CultureInfo( en-CA, true );
String recdate1 = txtrecdate.Text.Trim()。ToString();
DateTime recdate2 = DateTime.Parse(recdate1,provider,System.Globalization.DateTimeStyles.NoCurrentDateDefault);
objRetailPL.Amount = Convert.ToSingle(txtrecamount.Text.ToString());
objRetailPL.PartyName = partyname;
objRetailPL.Date = recdate2;
objRetailPL.Chequeno = txtchknumber.Text.ToString();
objRetailPL.username =会话[ username]的ToString();
dtinsert = objRetailBAL.InsertReceivedAmount(objRetailPL);
试试这个链接它可以帮助你
http://devilswork.wordpress.com/2009/03/27/gridview-row- edit-delete-and-update / [ ^ ]
http://www.c-sharpcorner.com/UploadFile/0c1bb2/insert-update-delete-in-gridview-using- single-stored-proce / [ ^ ]
http://forums.asp.net/t/1778323.aspx [ ^ ]
sheik
www.jobpencil.com [ ^ ]
how to write update query in gridview using code behind and then 1st column read only but another columns are editable then finally update the program pls help me
解决方案
<asp:GridView ID="GVAmountReceived" runat="server"DataKeyNames="sno" EmptyDataText="No Records Found" Style="margin-bottom: 6px" BorderColor="#BDBDBD" AllowPaging="true" PageSize="20"> <columns> <asp:templatefield headertext="S.No." footerstyle-horizontalalign="Center" itemstyle-horizontalalign="Center" xmlns:asp="#unknown"> <itemtemplate> <%# Container.DataItemIndex + 1 %> </itemtemplate> </asp:templatefield> <asp:boundfield headertext="Party Name" datafield="partyname" xmlns:asp="#unknown"> ItemStyle-HorizontalAlign="Center" ReadOnly="true" /> <asp:templatefield headertext="Date" itemstyle-horizontalalign="Center"> <edititemtemplate> <asp:textbox runat="server" id="txt_date" width="90px"></asp:textbox> <asp:calendarextender id="calrecdate" runat="server" targetcontrolid="txt_date" onclientdateselectionchanged="checkDate" format="dd/MM/yyyy" enabled="True" /> <asp:requiredfieldvalidator id="RFVrecdate" runat="server" controltovalidate="txt_date"> Display="None" ErrorMessage="Must Enter Date" ValidationGroup="duereport"></asp:requiredfieldvalidator> <asp:validatorcalloutextender id="VCErecdate" runat="Server" targetcontrolid="RFVrecdate" /> </edititemtemplate> </asp:templatefield> <asp:commandfield showeditbutton="true" headertext="Edit" validationgroup="duereport" /> </asp:boundfield></columns>
.cs page like this
DataTable dtinsert = new DataTable(); //TextBox txtparty = (TextBox)GVAmountReceived.Rows[e.RowIndex].Cells[1].Controls[1]; //DropDownList ddlparty = (DropDownList)GVAmountReceived.Rows[e.RowIndex].Cells[1].Controls[1]; TextBox txtrecdate = (TextBox)GVAmountReceived.Rows[e.RowIndex].Cells[3].Controls[1]; TextBox txtrecamount = (TextBox)GVAmountReceived.Rows[e.RowIndex].Cells[4].Controls[1]; TextBox txtchknumber = (TextBox)GVAmountReceived.Rows[e.RowIndex].Cells[5].Controls[1]; string partyname = Convert.ToString(GVAmountReceived.DataKeys[e.RowIndex].Values[0].ToString()); IFormatProvider provider = new System.Globalization.CultureInfo("en-CA", true); String recdate1 = txtrecdate.Text.Trim().ToString(); DateTime recdate2 = DateTime.Parse(recdate1, provider, System.Globalization.DateTimeStyles.NoCurrentDateDefault); objRetailPL.Amount = Convert.ToSingle(txtrecamount.Text.ToString()); objRetailPL.PartyName = partyname; objRetailPL.Date = recdate2; objRetailPL.Chequeno = txtchknumber.Text.ToString(); objRetailPL.username = Session["username"].ToString(); dtinsert = objRetailBAL.InsertReceivedAmount(objRetailPL);
Try This Links It May Help You
http://devilswork.wordpress.com/2009/03/27/gridview-row-edit-delete-and-update/[^]
http://www.c-sharpcorner.com/UploadFile/0c1bb2/insert-update-delete-in-gridview-using-single-stored-proce/[^]
http://forums.asp.net/t/1778323.aspx[^]
sheik
www.jobpencil.com[^]
这篇关于asp.net中的gridview控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文