Solved

Gridview Nested ASP.NET Multiple values

Posted on 2014-09-26
3
905 Views
Last Modified: 2014-09-29
I am writing a asp.net website and am running into an issue currently.

I have built a nested gridview following the following site - http://stackoverflow.com/questions/18533165/a-nested-gridview-example
I however am running into a little issue.

I altered the code to work how I wanted and am achiving somewhat of what I need.

Currently it shows in the parent gridview two columns - "Sender" and Recieved Date"
The drop down is pulling from the same sql table.

Whe I expand, it is showing me all records for that particular id not just the one pertaining to the specific entry.

I know what needs to be done but not how to implement it.

I want it to fill the drop down box with just the single records from SQL where the id matches, the sender matches and the recieved date matches.


here is my C#
 private static DataTable GetData(string query)
    {
        string strConnString = "Data Source=192.168.2.121\\EMMSDE;Initial Catalog=EMDB;User ID=jsmith;Password=s5993153492";
        using (SqlConnection con = new SqlConnection(strConnString))
        {
            using (SqlCommand cmd = new SqlCommand())
            {
                cmd.CommandText = query;
                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    using (DataSet ds = new DataSet())
                    {
                        DataTable dt = new DataTable();
                        sda.Fill(dt);
                        return dt;

                    }
                }
            }
        }
    }
    protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string from = gvCustomers.DataKeys[e.Row.RowIndex].Value.ToString();
            
            GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
            gvOrders.DataSource = GetData(string.Format("select  * from outlookreport.dbo.comlog where xrefid='{0}' ", from));
            gvOrders.DataBind();
            
            string phonenumber = e.Row.Cells[1].Text.ToString();
            int celllength = phonenumber.Length;
            string sender1 = e.Row.Cells[0].Text.ToString();
            int sendercount = sender1.Length;

            e.Row.Cells[1].Width = celllength + 2;
            e.Row.Cells[0].Width = sendercount + 10;
            gvOrders.Width = 420;
            
            
            //int cellwidth = Convert.ToInt32(e.Row.Cells[0].Width);
            //int emailwidth = Convert.ToInt32(e.Row.Cells[1].Width);
            //int hyperlinkwidth = Convert.ToInt32(e.Row.Cells[2].Width);
            //gvOrders.Width = cellwidth + emailwidth + hyperlinkwidth;

        }
    }

Open in new window


here is my asp
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" CssClass="Grid"
                            DataKeyNames="xrefid" OnRowDataBound="OnRowDataBound" Width="450px" Height="145px">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <img alt="" style="cursor: pointer" src="images/plus.png" />
                                        <asp:Panel ID="pnlOrders" runat="server" Style="display: none">
                                            <asp:GridView ID="gvOrders" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
                                                <Columns>
                                                    <%--       <asp:BoundField ItemStyle-Width="90px" DataField="Status" HeaderText="Status" />
                                                    <asp:BoundField ItemStyle-Width="90px" DataField="Location" HeaderText="Location" />--%>
                                                    <asp:HyperLinkField ItemStyle-Width="100%" ItemStyle-Wrap="false" DataNavigateUrlFields="Location" DataNavigateUrlFormatString="{0}" Target="_blank"
                                                        HeaderText="Message Link" Text="Click to View Secure Message" NavigateUrl="TEST" AccessibleHeaderText="TEST" />



                                                </Columns>
                                            </asp:GridView>
                                        </asp:Panel>
                                    </ItemTemplate>
                                </asp:TemplateField>
                                <asp:BoundField ItemStyle-Width="1200px" DataField="Sender" HeaderText="Sender" ItemStyle-Wrap="false" />
                                <asp:BoundField ItemStyle-Width="200px" DataField="DateRec" HeaderText="Recieved" />
                            </Columns>
                        </asp:GridView>

Open in new window


Java script -

   <script type="text/javascript">
        $("[src*=plus]").live("click", function () {
            $(this).closest("tr").after("<tr><td></td><td colspan = '1000'>" + $(this).next().html() + "</td></tr>")
            $(this).attr("src", "images/minus.png");
        });
        $("[src*=minus]").live("click", function () {
            $(this).attr("src", "images/plus.png");
            $(this).closest("tr").next().remove();
        });
        $(document).ready(function () {
            $("#textbox").val('');
            $("#textbox").keypress(function () {
                var textLength = $("#textbox").val().length;
                if (textLength % 50 == 0) {
                    var height = textLength / 50;
                    $("#textbox").css('height', 20 + (height * 20));
                }
            });
            $('#textbox').keydown(function (e) {
                if (e.keyCode == 13) {
                    var msg = $(this).val();
                    if (msg == "") {
                        alert('full the message');
                    }
                    else {
                        $(".commentsblock").append(
                        "<div class='comments'><div class='imageicons divfloat'><img src='https://cdn1.iconfinder.com/data/icons/black-easy/32/538647-user_32x32.png' /></div><div class='commentinfo divfloat'>" + msg + "</div></div>"
                        ).fadeIn('slow');
                        $("#textbox").val("");
                    }
                }
            })
        });
    </script>

Open in new window


CSS -
/*This is Where the parent gridview is and is the css for the content under borrower and address*/
.Grid td {
    background-color: #e4e0e0;
    color: black;
    font-size: 10pt;
    line-height: 200%;
    margin-left: 40px;
    border-width: 0px;
    border-top: solid 1px;
}
/*This is the headers of the parent gridview*/
.Grid th {
    background-color: #e4e0e0;
    color: black;
    font-size: 10pt;
    line-height: 200%;
    border-width: 0px;
    text-align: left;
}
/*Child Grid*/
.ChildGrid td {
    background-color: #eee !important;
    color: black;
    font-size: 10pt;
    border-width: 0px;
}
/*body for child grid*/
.ChildGrid th {
    background-color: #6C6C6C !important;
    color: White;
    font-size: 10pt;
    line-height: 200%;
    border-width: 0px;
}

.Grid {
    font-weight: 700;
    border-width: 0px;
}

Open in new window


See pictures below

Communication HIstory
Where it shows multiple links for "Click to view Secure Message" I want it to only display the one record that relates to the parent drop down.

So "Bob Thompson" would only have 1 drop down because it would match the Sender and the Received date on it from the query.
0
Comment
Question by:desiredforsome
  • 2
3 Comments
 
LVL 12

Accepted Solution

by:
Ramkisan Jagtap earned 500 total points
ID: 40349303
please change your query to:

gvOrders.DataSource = GetData(string.Format("select  * from outlookreport.dbo.comlog where xrefid='{0}' and sender='{1}' and received='{2}' ", from, sender, received));
0
 

Author Comment

by:desiredforsome
ID: 40349803
I am not sure I understand that query.

Here is a shot of my actual sql db I am testing with.

do I need to delare these variables at al?

Like
string sender = gvcustomers.datakeys... ?

SQL
0
 

Author Closing Comment

by:desiredforsome
ID: 40349893
I had to make some adjustments becuase the date would not convert so I added an ID number in the SQL

Code is like this protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            string from = gvCustomers.DataKeys[e.Row.RowIndex].Values[0].ToString();
            string sender25 = gvCustomers.DataKeys[e.Row.RowIndex].Values[2].ToString();
            string recieved = gvCustomers.DataKeys[e.Row.RowIndex].Values[1].ToString();
            //DateTime recieveddate = gvCustomers.DataKeys[e.Row.RowIndex].Values[1];
            GridView gvOrders = e.Row.FindControl("gvOrders") as GridView;
            gvOrders.DataSource = GetData(string.Format("select  * from outlookreport.dbo.comlog where xrefid='{0}' and sender='{1}' and id='{2}'", from, sender25,recieved));
            //gvOrders.DataSource = GetData(string.Format("select  * from outlookreport.dbo.comlog where xrefid='{0}' and daterec='{1}' ", from));
            gvOrders.DataBind();
         
            string phonenumber = e.Row.Cells[1].Text.ToString();
            int celllength = phonenumber.Length;
            string sender1 = e.Row.Cells[0].Text.ToString();
            int sendercount = sender1.Length;

            e.Row.Cells[1].Width = celllength + 2;
            e.Row.Cells[0].Width = sendercount + 10;
            gvOrders.Width = 420;
           
           
            //int cellwidth = Convert.ToInt32(e.Row.Cells[0].Width);
            //int emailwidth = Convert.ToInt32(e.Row.Cells[1].Width);
            //int hyperlinkwidth = Convert.ToInt32(e.Row.Cells[2].Width);
            //gvOrders.Width = cellwidth + emailwidth + hyperlinkwidth;

        }
    }
0

Featured Post

How our DevOps Teams Maximize Uptime

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

Question has a verified solution.

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

ASP.Net to Oracle Connectivity Recently I had to develop an ASP.NET application connecting to an Oracle database.As I am doing it first time ,I had to solve several problems. This article will help to such developers  to develop an ASP.NET client…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

713 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