Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 22-Dec-13 23:06pm
v2
Comments
JoCodes 23-Dec-13 5:00am    
What you have tried so far?
Gaurav Makwana 23-Dec-13 5:12am    
just write update query for gridview and think bro its easy task
Member 10433948 23-Dec-13 5:45am    
my concept is
gridview 1st column data bound with readonly and 2nd,3rd and 4th column is editable
then finally update the 1st row when i goto the 2nd row .
pls help
Gaurav Makwana 23-Dec-13 5:15am    
first select gridview column by this line
Int32 selectedrowcount = dataGridView1.Rows.GetRowCount(DataGridViewElementStates.Selected);

now if(selectedrowcount > 0) thne
write update query its solve
Gaurav Makwana 23-Dec-13 6:39am    
there is property read only true or false
hope you know about fetch column or row then set the readonly property false

datagridview1.columns["name"].readonly = true;
then

when you fetch 4 put it readonly false

VB
<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

C#
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);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900