开发者

Handling Depth of embedded Repeaters

开发者 https://www.devze.com 2023-01-25 17:05 出处:网络
I have a design question. I have a nested repeater structure that is 4 tiers deep. The repeaters display data that are deemed as \"Sections 1-4\". These sections are all tied in a database to a Job De

I have a design question. I have a nested repeater structure that is 4 tiers deep. The repeaters display data that are deemed as "Sections 1-4". These sections are all tied in a database to a Job Description.

I want to add an edit button to each item in the deepest tier of the repeaters. However, the repeater depths are not all equivalent. A job description can have multiple entries for each Section (1-4), thus the need for repeaters. The catch though, as stated previously, is that a given entry of sections may be 1-3 ... then 1-4... maybe even just the first section.

One additional precondition that makes this tricky is that it was designed to only bind to one tier at a time. Then they click a drill down img button which binds the next set of data to the inner repeater. So this makes it more difficult than simply counting the number of times you bind to it.

So my question is what programming construct could I employ that would be relatively fast to deduce the depth of a given entry? Obviously, a solution that wouldn't require a lage additional chunk of time would be amazing considering I have a due date.

Here is the table structure. Bear in mind that it is not changeable. It was before more time.

 Table       FK         PK
Section1 |  JobID   | Sect1ID |
Section2 |  Sect1ID | Sect2ID |
Section3 |  Sect2ID | Sect3ID |
Section4 |  Sect3ID | Sect4ID |

Repeater Structure

<Repeater 1>
     <Section 1 Data>
     <Repeater 2>
          <Section 2 Data>          
          <Repeater 3>
               <Section 3 Data> 
               <Repeater 4>
                    <Section 4 Data>
               </Repeater>
           </Repeater>
      </Repeater>
 </Repeater>

Some of my ideas.

Create a stored procedure that calculates the depth of an entry. Pass in SectID and it returns the de开发者_Python百科pth relative to the SectID. I already have a structure in place to identify each individual repeater item by Section ID via a hidden asp:label.

Maintain a dictionary for mapping a section to its depth. Utilize the stored procedure. However, only an entry when an item is drilled. This way it is lightweight, and i only track the items the user is interested in.

Each time the user drills down, perform a check to see if the depths are equal ... if they are, then display the edit img button, if not, then drill and increment the value in the dictionary.

any other ideas or issues they foresee with my solution?


The answer was actually pretty straight forward. performing all that tracking was a clumsy approach at best. The solution is much simplier than that. I am not the most proficient Stored Procedure writer so bear with me on that count. If anyone is inclined to show a more maintainable and neat version that would be awesome!

The solution is to create a set of stored procedures that peeks at the next section record associated with it

bit doesSection2RecordExist(int prevSectID)
bit doesSection3RecordExist(int prevSectID)
bit doesSection4RecordExist(int prevSectID)

these all return a bit i.e True or False about the statement implied by the name of the SP

now just tie these into a neat method as so (keep in mind, my company is using a Schema approach so the db access code may look somewhat foreign to some but the db access implementation details are not a dependancy you need be concerned with.

    public enum SectionType { First, Second, Third, Fourth };

    public static bool HasNextSection(int prevSectID, SectionType sectNum)
    {
        if (sectNum > SectionType.First)
        {
            var procName = "Section" + (int)sectNum + "RecordExists";
            using (var ov = new OneValue(Product.SafetyObs, procName))
            {
                ov["PrevSectID"] = prevSectID;
                return ov.Value.Bool;
            }
        }
        return false;
    }

The final step is making the call at the appropriate time to check if there is another record a tier deeper. This is done in the OnBound event of the Repeater

Another note is that I made grabbing the correct previous Section ID more simplified. I store it at each tier level in a Label during binding time and make it invisible.

protected void rptrSection1_Bound(object sender, RepeaterItemEventArgs e)
    {                        
        var lblID = e.Item.FindControl("lblSection1Id") as Label;
        var sectID = int.Parse(lblID.Text);

        if (!SectionLoader.HasNextSection(sectID, SectionType.Second))
        {
            //things to do if there are no sections left
        }
        else
        {
            //things to do if there are sections left
        }

        return;
    }

and then I just repeat that with all the inner repeaters 2-4

I hope this helps for anyone running into something similar in the future!!

0

精彩评论

暂无评论...
验证码 换一张
取 消