Solved

Gridview Nested ASP.NET Multiple values

Posted on 2014-09-26
3
959 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
[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
  • 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

623 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