[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 379
  • Last Modified:

aspx repeater value to usercontrol

Have an aspx page containing a repeater also a ModalPopup. I would like the user to select the item on the repeater and then from the code behind load the usercontrol into the modalpopup with the information from the database that the usercontol handles. One value will need to be passed.

I work with VB but can read and convert C#.

I have some code attached but does not work.
Protected Sub bDL_MessageCenter_ItemCommand(ByVal source As Object, ByVal e As RepeaterCommandEventArgs) Handles DL_MessageCenter.ItemCommand
        Dim MessageID As Integer = Convert.ToInt32(e.CommandArgument)
        'lblMsgBox.Text = MessageID.ToString
        Control1.userName = Convert.ToInt32(e.CommandArgument)
        Dim Setup_Countriestoload As Control = Me.LoadControl("~\Message_center.ascx")
        Control1.Controls.Add(Setup_Countriestoload)
        mpe.Show()
    End Sub


<asp:UpdatePanel ID="ud_Setup_Countries" runat="server" UpdateMode="Conditional">
            <ContentTemplate>
                <uc1:Control ID="Control1" runat="server" userName="" />
            </ContentTemplate>
        </asp:UpdatePanel>


'.ascx


    Public Property userName() As String
        Get
            Return _userName
        End Get
        Set(ByVal value As String)
            _userName = value
        End Set
    End Property



'I was thinking something like this might work but can't get it to work

    Private _DDLDate As String
    Public Property DDLDate() As RepeaterCommandEventArgs
        Get
            Return DDLDate.CommandArgument.ToString
        End Get
    End Property

Open in new window

0
crundle
Asked:
crundle
  • 4
  • 3
1 Solution
 
Jini Jose.Net Team LeadCommented:
if conversion is the only problem then you can use the below online utility to convert vb to c# or back

http://www.developerfusion.com/tools/convert/vb-to-csharp/
0
 
crundleAuthor Commented:
conversion is NOT an issue, I stated this just in case C# people replied to let them know it was not a problem.
0
 
Jini Jose.Net Team LeadCommented:
so you have to show some data based on the repeaters data ?

for rg:

if the repeater has the following data
A
B
C

so when click on A you have to show the A's records from db in that user control ..

right ??
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
crundleAuthor Commented:
On the aspx page have linkbuttons from listed from a repeater - no problem
select the linkbutton but the value does not carry over to the usercontrol (ascx) for the data to be pulled using the selected linkbutton

getting the value on the aspx page is fine but the usercontrol gets an empty string, so default value is used.
0
 
crundleAuthor Commented:
I've requested that this question be deleted for the following reason:

never was response to question
0
 
Jini Jose.Net Team LeadCommented:
sorry for the late reply. kindly check the below codes.
// here is your repeater control

<asp:Repeater ID="rep" runat="server">
            <ItemTemplate>
                <uc1:Emp ID="Emp1" runat="server" EmployeeCode='<%# Eval("code") %>' />
            </ItemTemplate>
            <SeparatorTemplate>
                <br />
            </SeparatorTemplate>
        </asp:Repeater>

please note the i added a new property called EmployeeCode in the user control.


//here is user control


<asp:LinkButton ID="l1" runat="server"></asp:LinkButton>
<asp:Panel ID="MyPanel" runat="server" CssClass="modalPopup" Style="display: none;">
    <table>
        <tr>
            <td>
                Employee Code
            </td>
            <td>
                <asp:Label ID="empCode" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Name
            </td>
            <td>
                <asp:Label ID="empName" runat="server"></asp:Label>
            </td>
        </tr>
        <tr>
            <td>
                Gender
            </td>
            <td>
                <asp:Label ID="empGender" runat="server"></asp:Label>
            </td>
        </tr>
    </table>
    <asp:Button ID="CancelBtn" Text="OK" runat="server" />
</asp:Panel>
<cc1:modalpopupextender id="Mpe1" targetcontrolid="l1" cancelcontrolid="CancelBtn"
    popupcontrolid="MyPanel" runat="server" backgroundcssclass="modalBackground" />

//here is user control code behind

public string EmployeeCode
        {
            set
            {
                l1.Text = value;

                string ConString = @"Data Source= jini\sqlexpress;Initial Catalog=Test;User ID=sa;Password=sql2005;Pooling=true;Connect Timeout=600;";
                string Query = "select code,name,gender,dob from employee where code='" + value + "'";
                DataSet ds = new DataSet();
                SqlConnection oCon = new SqlConnection(ConString);
                oCon.Open();
                SqlCommand oCmd = new SqlCommand(Query, oCon);
                SqlDataAdapter oDa = new SqlDataAdapter(oCmd);
                oDa.Fill(ds);
                oDa = null;
                oCmd = null;
                oCon.Close();
                oCon = null;

                empCode.Text = value;
                if (ds.Tables[0].Rows.Count > 0)
                {
                    empName.Text = ds.Tables[0].Rows[0]["name"].ToString();
                    empGender.Text = ds.Tables[0].Rows[0]["Gender"].ToString();
                }
            }
        }    
0
 
crundleAuthor Commented:
want to accept solution
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now