顯示具有 Repeater 標籤的文章。 顯示所有文章
顯示具有 Repeater 標籤的文章。 顯示所有文章

2014年7月13日 星期日

[RESOLVED] calling Checkbox checked Event


I've a repeater and in repeater i've check box list..wheck is generated dynamically.


How i can call check box checked Even


here is code








<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server">









Set cbl Autopostback="true"


CheckedChanged event is for CheckBox instead CheckBoxList


CheckBoxList is using SelectedIndexChanged


This sample for CheckBox


    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
RepeaterItem ri = (RepeaterItem)cb.NamingContainer;
HiddenField hdngrpOpid = (HiddenField)ri.FindControl("hdngrpOpid");
int idx = ri.ItemIndex;




}












<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server" AutoPostBack="true" onselectedindexchanged="cbxControl_SelectedIndexChanged" >





On Code Behind
protected void cbxControl__SelectedIndexChanged(object sender, EventArgs e)
{

}


[RESOLVED] Online Examination system


I am working in a project on online examination systm in which  i have binded radiobuttons in formview and value in radiobuttons comes from  database where i have stored options for particular question...


Now i want to know how to save value of radiobutton option that was choosen by user and how to move on next question when user clicks on next button..



 Plz if anyone of you can help...



Hi,


To Save selected radio button option in database check this,


http://www.c-sharpcorner.com/blogs/8328/insert-radiobutton-values-into-database.aspx


I assume that your questions are coming from database, same kind of scenario is discussed here,


http://forums.asp.net/t/1918270.aspx/1?Display+Data+in+Textbox+Next+Previous+First+Last+form+database+in+asp+net+and+c+


You can use repeater control to show questions and options one at a time.


Hope this helps!



on button click event, u can read value from radiobuttonlist


string strSelectRadio = ((RadioButtonList) FormView1.FindControl("radio_buttonlist_id")).SelectedValue;


then, store value of strSelectedRadio in database and again fetch next question from database and rebind formview


hope this helps...


[RESOLVED] calling Checkbox checked Event


I've a repeater and in repeater i've check box list..wheck is generated dynamically.


How i can call check box checked Even


here is code








<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server">









Set cbl Autopostback="true"


CheckedChanged event is for CheckBox instead CheckBoxList


CheckBoxList is using SelectedIndexChanged


This sample for CheckBox


    protected void CheckBox1_CheckedChanged(object sender, EventArgs e)
{
CheckBox cb = (CheckBox)sender;
RepeaterItem ri = (RepeaterItem)cb.NamingContainer;
HiddenField hdngrpOpid = (HiddenField)ri.FindControl("hdngrpOpid");
int idx = ri.ItemIndex;




}












<%#GetGroupName(Eval("MENU_MODIFIER_GROUP_NAME_TRANSLATION_ID").ToString().Trim())%>
[Free :
<%#GetFreeQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]   [max:

<%#GetMaxQuantity(Eval("MENU_MODIFIER_GROUP_ID").ToString().Trim())%>
]






<%-- --%>
runat="server" AutoPostBack="true" onselectedindexchanged="cbxControl_SelectedIndexChanged" >





On Code Behind
protected void cbxControl__SelectedIndexChanged(object sender, EventArgs e)
{

}


[RESOLVED] Online Examination system


I am working in a project on online examination systm in which  i have binded radiobuttons in formview and value in radiobuttons comes from  database where i have stored options for particular question...


Now i want to know how to save value of radiobutton option that was choosen by user and how to move on next question when user clicks on next button..



 Plz if anyone of you can help...



Hi,


To Save selected radio button option in database check this,


http://www.c-sharpcorner.com/blogs/8328/insert-radiobutton-values-into-database.aspx


I assume that your questions are coming from database, same kind of scenario is discussed here,


http://forums.asp.net/t/1918270.aspx/1?Display+Data+in+Textbox+Next+Previous+First+Last+form+database+in+asp+net+and+c+


You can use repeater control to show questions and options one at a time.


Hope this helps!



on button click event, u can read value from radiobuttonlist


string strSelectRadio = ((RadioButtonList) FormView1.FindControl("radio_buttonlist_id")).SelectedValue;


then, store value of strSelectedRadio in database and again fetch next question from database and rebind formview


hope this helps...


[RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


Hi All,


Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


.ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you




    [RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


    Hi All,


    Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


    .ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you




    [RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


    Hi All,


    Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


    .ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you




    [RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


    Hi All,


    Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


    .ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you




    [RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


    Hi All,


    Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


    .ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you




    [RESOLVED] Not able to Hide/remove a ChildNode from a Repeater bound to SitemapDatasource


    Hi All,


    Please help me to hide/remove a child node. I am able to hide a nodeby setting visible property to false but not able to hide a child node. My code


    .ASPX CODE





  • <%# Eval("Title") %>






    • <%# Eval("Title") %>










  • Code Behind Code on Repeater OnItemDataBound="menu_ItemDataBound":


    SqlDataSource SqlDataSource1 = new SqlDataSource();
    SqlDataSource1.ConnectionString = ConfigurationManager.ConnectionStrings["IDMServicesDatabaseConnectionString"].ConnectionString;

    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    node.ChildNodes.Remove(node); }
    }
    }

    }


    }

    Not able to either remove or hide(by setting the visible property) the child node. With the above code to remove node.ChildNodes.Remove(node) getting Collection is read only not supported exception.


    Please help



    Any help would be appreciated...



    i think following line is problematic,


    node.ChildNodes.Remove(node);

    you are trying do delete node from node object, self-delete is not possible :)


    instead try this


      node.ChildNodes.RemoveAll();     OR   node.ChildNodes.Clear();    

    Thanks.








    ijaz_asp



    instead try this


     node.ChildNodes.RemoveAll(); OR node.ChildNodes.Clear(); 




    same error "Collection is Read only" for node.ChildNodes.Clear();  Method Removeall(); does not exist at all



    hmm, if this is the case , try to hide the item instead of deleting it. like if the data-bound item does not fullfill your display/visible logic then get it from template object and set its visibility to none or simply set visible=false.


    thanks



    I am able to set the Visible property (e.Item.Visible =
    false;)
    for the Parent node in ItemDataBound(object
    sender,
    RepeaterItemEventArgs e) but not able to hide the
    hyperlink which is dynamically created using repeater control.


    Please help me with an example



    it may be something like this,


    var hyperlink = e.Item.findControl("ID of HyperLink") as HyperLink;

    if(hyperlink !=null)
    {
    hyperlink.visible=false; // if it does not meet your criteria .
    }

    thanks





    These hyperlinks are dynamically generated in a repeater control. Not sure of the ID.



    Hi,


    The id is you set in makeup code



    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
    {
    SiteMapNode thisMapNode = (SiteMapNode)e.Item.DataItem;
    thisMapNode.ReadOnly = false;
    if (thisMapNode.Title == "Admin")
    {
    if (Page.User.IsInRole("enterprisenet.org\\gbs idm Shift leads"))
    {
    e.Item.Visible = true;
    }
    else
    {
    e.Item.Visible = false;
    }
    }
    else
    {
    SiteMapNodeCollection siteMapCollection = thisMapNode.ChildNodes;
    foreach (SiteMapNode node in siteMapCollection)
    {
    string requestType = node.Title;
    SqlDataSource1.SelectCommand = "SELECT [Visible] FROM [IDMServicesList] where [RequestType]='" + requestType + "'";
    //SqlDataSource1.SelectParameters.Add("RequestType", requestType);
    DataView dv = (System.Data.DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
    if (dv.Count > 0)
    {
    DataRowView drv = dv[0];
    string Visible = drv["Visible"].ToString();
    if (Visible == "Hide")
    {
    Repeater thisRepeater = (Repeater)e.Item.FindControl("Repeater1"); HyperLink thisLink = (HyperLink)thisRepeater.FindControl("HyperLink2"); thisLink.Visible = false; }
    }
    }
    }
    }

    I have implemented your code but on the runtime thisLink is null. On thisLink.Visisble, I get object reference not set to instance of an object.






  • <%# Eval("Title") %>






    • <%# Eval("Title") %>









  • On the Repeater1 (Inside the menu Repeater) databound event, I am able to find the id of Hyperlink


    HyperLink thisLink = (HyperLink)e.Item.FindControl("HyperLink2");
    if (thisLink != null)
    {
    thisLink.Visible = false;
    }

    Not sure y your code did not work



    Hi,


    Try it like this


     NavigateUrl='<%# Eval("Url") %>'><%# Eval("Title") %>

    And in code behind define the method isVisible()


    public bool isVisible() 
    {
    if (something ...)
    return true;

    else
    return false;
    }

    And refer the thread


    http://stackoverflow.com/questions/10199698/set-visible-of-a-label-from-code-behind


    http://forums.asp.net/t/1409887.aspx/1


    Hope it can help you