Solved

Need help with EDIT updates in an ASP.NET Gridview...

Posted on 2014-10-23
6
349 Views
Last Modified: 2014-11-25
Have an ASP.NET GridView...  4 columns, with autogenerated EDIT column.

                <asp:GridView ID="ContactGridView" runat="server"
                    AutoGenerateColumns="False"
                    BackColor="#DEBA84" 
                    BorderColor="#DEBA84" 
                    BorderStyle="None" 
                    BorderWidth="1px" 
                    CellPadding="5"
                    CellSpacing="3"
                    DataKeyNames="ContactUs_key"
                    DataSourceID="SqlDataSource1"
                    HeaderStyle-HorizontalAlign="Center"
                    HeaderStyle-Wrap="True"
                    HorizontalAlign="Center"
                    onselectedindexchanged="ContactGridView_SelectedIndexChanged"
                    SelectedRowStyle-BackColor="Wheat" >
                    <Columns>
                        <asp:CommandField ShowEditButton="True" />
                        <asp:BoundField DataField="ContactUs_key" HeaderText="Key" ItemStyle-HorizontalAlign="Center" ReadOnly="True" InsertVisible="False" SortExpression="ContactUs_key" Visible="false" >
                        </asp:BoundField>
                        <asp:TemplateField HeaderText="Status" SortExpression="ContactUs_status">
                            <EditItemTemplate>
                                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" SelectedValue='<%# Bind("ContactUs_status", "{0}") %>'>
                                    <asp:ListItem Value="I">In Progress</asp:ListItem>
                                    <asp:ListItem Value="C">Complete</asp:ListItem>
                                </asp:DropDownList>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <asp:Label ID="Label1" runat="server" Text='<%# Bind("ContactUs_status") %>'></asp:Label>
                            </ItemTemplate>
                            <ItemStyle HorizontalAlign="Center" />
                        </asp:TemplateField>
                        <asp:BoundField DataField="ContactUs_last_name" HeaderText="Last Name" SortExpression="ContactUs_last_name" ReadOnly="true" />
                        <asp:BoundField DataField="ContactUs_processedDate" HeaderText="Last Update" SortExpression="ContactUs_processedDate" DataFormatString="{0:d}" ItemStyle-HorizontalAlign="Center" >
                        <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                        <asp:BoundField DataField="ContactUs_processedBy" HeaderText="Updated By" SortExpression="ContactUs_processedBy" ItemStyle-HorizontalAlign="Center" >
                        <ItemStyle HorizontalAlign="Center" />
                        </asp:BoundField>
                    </Columns>
                </asp:GridView>

Open in new window



I have Edit Button, Status, Processed Date and Processed By  columns.

If the edit option is used to change the status.  I just want to plug the 2 "Processed" fields with data.
Plug the DATE with Date.NOW  and use a hidden.control.text  value for the BY column.

I thik that it has something to do with the "onselectedindexchanged" option.  I would basically write my own SQL code for that in the code-behind, but HOW do I get the right column updated as it should be?

Bob
0
Comment
Question by:Bob Bender
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
6 Comments
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40402147
Hi,

Your question is very difficult to understand.
0
 
LVL 5

Author Comment

by:Bob Bender
ID: 40402358
Oh, in what way????  

Lemme try English....   ROFL

I have multiple columns...   "Edit Button", "Status", "Processed Date" and "Processed By".

If the Edit Button is used to change the record....   I can change the other 3 columns.... "Status", "Processed Date" and "Processed By".

Instead of actually changing  the "Processed Date" and "Processed By", I want to just "plug" those fields with valid data and not rely on the user to fill it in correctly....

I have tried various method options within the GridView,  (like onrowupdated, onrowupdating, onselectedindex, etc)  

All things I have done in the past are referenced by columns, with a 0 relative base,   NOT 1-9, but 0-8.   But, the combination of column "index" and what stage in the process to "plug" the data confuses me....

I could go into the database and UPDATE the fields and re-bind the GridView on the page..  

It would be cleaner (and learning more) to let the changes be made when handling the EDIT/UPDATE processes of GridView...

Clearer?
0
 
LVL 29

Expert Comment

by:sammySeltzer
ID: 40402455
Lemme try English....   ROFL


First of all, you need to understand that there are exceptionally talented helpers here at EE.

So, if there are no attempts at answering your question, one of the most common reasons is that your question is not clear enough for anyone to attempt an answer.

So, to suggest that your question is so clear and it is us who have problem understanding it is a bit condensing.

I use every opportunity that I have to remind those seeking help that *we* provide this help absolutely free.

I am not obligated in any way to help you or anyone.

I am motivated to help because I have been helped many times by those who abandon the work that pays them to help.

NOW, having said this, your ability to have cascading updates based on a set of criteria is based largely on your data structure.

So, to change the value of one field and then have the values of associated fields change is based on the relationship between them.

Yes, it has to do with onselectedindexchanged.

For instance, assume I have a dropdownlist control like below:

 <asp:DropDownList ID="drop1" OnSelectedIndexChanged="drop1_SelectedIndexChanged" runat="server" CssClass="style26" AutoPostBack="True" />

Open in new window


Assume you wish to auto fill form field called myname:

     <strong>Fill Name</strong>Auto filled name)<br /><br /> </span>
                <asp:TextBox ID="myname" runat="server" CssClass="style26"></asp:TextBox>

Open in new window



Then the meat:

    Sub drop1_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
        myname.Text = CType(sender, DropDownList).SelectedValue

        'Did I get what I asked for?
        Response.Write(myname)
        Response.End()
    End Sub

Open in new window


Example above is based on passing same value from dropdown to myname.Text control.

In your case, you will assign associated value from your database to a recordset inside the drop1_SelectedIndexChanged() sub, something along the lines of:

   Dim connStr As String = ConfigurationManager.ConnectionStrings("Database_DBConnectionString").ConnectionString

       sqlStr = "SELECT * FROM yourtable WHERE id= drop1.selectedValue

      cnn = New SqlConnection(connStr)
     cnn.Open()
   cmd = New SqlCommand(sqlStr, cnn)

   Dim dreader = cmd.ExecuteReader()

      If dreader.Read() Then
          fullname = dreader.GetString(0)
    End If
    dreader.Close()

'Finally, pass value back to the textbox control associated with drop1

myname.Text = fullname

Open in new window

0
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 5

Author Comment

by:Bob Bender
ID: 40412491
TYou said....
So, to suggest that your question is so clear and it is us who have problem understanding it is a bit condensing.


Sammy,  Just an FYI... the word is condescending, not condensing..

And IMHO, I never said it was so clear that anyone could understand it.  You did, so please do not put words in my mouth (apologies if you are offended by this point of view)  Gee whiz, a person cant have a slight sense of humor

I clarified the comments and description to best of my Junior capabilities.  I' have to review the rest of your reply at the PC where the devl is being done, as I have no access to the db to test outside the environment.

As for "neglect and abandoning" the post.  maybe my marriage was not so important to put things on hold here.
That's a joke son (as Foghorn Leghorn used to say in the cartoons in the 70s)
0
 
LVL 5

Accepted Solution

by:
Bob Bender earned 0 total points
ID: 40415707
Okay, your code and "understanding" of my question is not clear.

I have a GRIDVIEW....  I change Column 2 (say status) using a drop-down box (this works).

As I make that change...  I ALSO want to default Columns 9 (Date Changed) and Columns 10 (Changed By).   I want the new values to be shown on The Gridview after using the UPDATE link.

You seem to be changing a TextBox by the value associated with a drodown.  Nothing like I need.  

Also, the question was a C# condition and it seems that this is VB code. (but should be easy to change, had it applied.)

Bob
0
 
LVL 5

Author Closing Comment

by:Bob Bender
ID: 40464141
Unable to delete

I solved it thru use of the Find.Control and binding to it
0

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

630 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question