Solved

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

Posted on 2014-10-23
6
339 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
  • 4
  • 2
6 Comments
 
LVL 28

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 28

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
Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

 
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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Injector with Web Service 4 40
HttpPostedFile 1 26
Database Connections Not being returned to Connection Pool 7 25
ASP.NET MVC -Add authentication 2 21
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

770 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