I am using IG Webtab in one of my project.I have two tabs say Tab1 and Tab2.I have dropdown inside this webtabs and Onselected index chnage event i am fetching dropdown's value to textbox.It works fine for tab1 but when i am selecting value from dropdown in Tab2.it is binding value to textbox of Tab1.
Hello Ankita,
Can you please add a runnable code sample so I can see how the binding is set and test the actual code locally?
Thanks in advance!
On main page i have tab as below
<ig:WebTab ID="tabMatric" runat="server" Height="550px" EnableViewState="true"> <ClientEvents Loaded="tabMatric_Loaded" SelectedIndexChanging="tabSelectedIndexChanging" /> </ig:WebTab>
On Repeater control I have below code
<asp:Repeater ID="repQuestionnaire" runat="server" EnableViewState="True" OnItemDataBound="repQuestionnaire_ItemDataBound" OnItemCreated="repQuestionnaire_ItemCreated"> <ItemTemplate> <table cellpadding="3" width="98%"> <tr>
<td width="100%"> <span class="QuestionText"> <asp:RadioButtonList ID="rblResponses" runat="server" RepeatColumns="1" AutoPostBack="true" OnSelectedIndexChanged="rblResponses_SelectedIndexChanged" EnableViewState="true" /> <asp:HiddenField ID="hfresponses" runat="server" /> <div> <asp:DropDownList ID="ddlcomment" AutoPostBack="true" runat="server" Enabled="true" EnableViewState="true" OnChange="GetSelectedTextValue(this)" OnSelectedIndexChanged="ddlcomment_SelectedIndexChanged1" ></asp:DropDownList> </div> <div id="divComments" runat="server" style="display: none"> <table style="width: 95%" cellpadding="1"> <tr> <td class="print" align="right"> <asp:HyperLink ID="lnkSpellCheck" runat="server" Text="Check Spelling" ></asp:HyperLink><br /> </td> </tr> <tr> <td> <%-- <asp:TextBox ID="txtComments" runat="server" TextMode="MultiLine" Width="100%" Height="90px" />--%> <uc4:uc_MultiLineLimitedCharacter ID="txtComments" runat="server" Width="100%" Height="100px" MaxLength="4000" /> </td>
</tr>
</table>
</Itemtemplate>
</asp:repeater>
Code behind repeater
protected void Page_Load(object sender, EventArgs e) {
if (qList != null && qList.Count() > 0) { repQuestionnaire.DataSource = qList; repQuestionnaire.DataBind(); }
protected void rblResponses_SelectedIndexChanged(object sender, EventArgs e) { int responseID = 0; string responseName = ""; // string MetricTab // int RadioResponseID = Convert.ToInt32(rblResponses.SelectedValue); foreach (RepeaterItem item in repQuestionnaire.Items) { // RadioButton rdbColour = item.FindControl("rdbColour") as RadioButton; RadioButtonList rblResponses = item.FindControl("rblResponses") as RadioButtonList; // DropDownList drpcomments = item.FindControl("drpComments") as DropDownList; // DropDownList drpCommentText = item.FindControl("ddlcommenttext") as DropDownList; DropDownList ddlcomment = item.FindControl("ddlcomment") as DropDownList;
if (rblResponses.SelectedIndex != -1) { responseID = Convert.ToInt32(rblResponses.SelectedValue); string responseText = rblResponses.SelectedItem.Text.ToString(); responseName = responseText.Substring(responseText.LastIndexOf(')') + 1).TrimStart(); CommentsMaintenanceSessionManager sessionMangercomments = new CommentsMaintenanceSessionManager(); List<BusinessEntities.CommentsMaintenance> clist = sessionMangercomments.Get(CommentsMaintenanceSessionManager.COMMENT_LIST) as List<BusinessEntities.CommentsMaintenance>;
BindCommentsDropdown(clist, responseName, ddlcomment); if ( hfddlcomment.Value != "") { ddlcomment_SelectedIndexChanged1( sender, e); } // ddlcomment_SelectedIndexChanged1(sender, e); } }
}
public void BindCommentsDropdown(List<CommentsMaintenance> CommentList, string responseName,DropDownList ddlcomment) { try { // int RadioResponseID = Convert.ToInt32(rblResponses.SelectedValue); List<BusinessEntities.CommentsMaintenance> commentList = new List<BusinessEntities.CommentsMaintenance>(); if (CommentList != null) { if (CommentList.Count > 0) { ddlcomment.DataSource = CommentList.Where(c => c.MetricID == this.metricId && c.ResponseName == responseName); ddlcomment.DataTextField = "CommentText"; ddlcomment.DataValueField = "CommentID"; ddlcomment.DataBind(); ddlcomment.Items.Insert(0, new ListItem("-- Select --", "Select")); } } else { using (BusinessProcess.CommentsMaintenace bpcommentsmaintenance = new BusinessProcess.CommentsMaintenace()) { List<BusinessEntities.ResponseCommentsMaintenance> ResponseList = new List<BusinessEntities.ResponseCommentsMaintenance>(); List<BusinessEntities.RiskThemeMetric> metricList = new List<RiskThemeMetric>(); //List<BusinessEntities.AdminCommentList> commentList = new List<AdminCommentList>();
int result = bpcommentsmaintenance.GetCommentsList(Period, ref ResponseList, ref metricList, ref commentList); if (commentList != null) { if (commentList.Count > 0) { ddlcomment.DataSource= commentList.Where(c => c.MetricID == this.metricId && c.ResponseName == responseName); ddlcomment.DataTextField = "CommentText"; ddlcomment.DataValueField = "CommentID"; ddlcomment.DataBind(); ddlcomment.Items.Insert(0, new ListItem("-- Select --", "Select")); ////drpComments.DataSource = commentList.Where(c => c.MetricID == this.metricId && c.ResponseName == responseName); //drpComments.DataTextField = "CommentText"; // drpComments.DataValueField = "CommentID"; // drpComments.DataBind();
} } } } } catch (Exception ex) {
protected void repQuestionnaire_ItemDataBound(object sender, RepeaterItemEventArgs e) { // This event is raised for the header, the footer, separators, and items.
// Execute the following logic for Items and Alternating Items. if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem) { #region "Find Controls from item..."
int questionId = Convert.ToInt32(((HiddenField)e.Item.FindControl("hfQuestionId")).Value);
string showCommentsAlways = ((Question)e.Item.DataItem).showComments; string displayType = string.Empty; bool bShowCommentsBox = false;
Literal ltrQuestionNo = (Literal)e.Item.FindControl("ltrQuestionNo"); if (ltrQuestionNo != null) ltrQuestionNo.Text = Convert.ToString(nCounter++);
HtmlGenericControl divComments = ((HtmlGenericControl)e.Item.FindControl("divComments"));
RadioButtonList rblResponses = ((RadioButtonList)e.Item.FindControl("rblResponses"));
if (rblResponses != null) { rblResponses.Attributes.Add("onclick", "javascript:setDirtyFlag(true);"); } RequiredFieldValidator rfvComments = ((RequiredFieldValidator)e.Item.FindControl("rfvComments")); UserControl UC_txtComment = ((UserControl)e.Item.FindControl("txtComments")); TextBox txtComments = ((TextBox)UC_txtComment.FindControl("txtMessage")); if (txtComments != null) { txtComments.Attributes.Add("onblur", "javascript:validateMin10AndMax4000StringChar(this);"); } /* Image btnSpellCheck = ((Image)e.Item.FindControl("btnSpellCheck")); if (btnSpellCheck != null && txtComments != null) btnSpellCheck.Attributes.Add("onclick", "javascript:WebSpellingCheck('" + this.WebSpellCheckerClientID + "','" + txtComments.ClientID + "')"); */ HyperLink btnSpellCheck = ((HyperLink)e.Item.FindControl("lnkSpellCheck")); if (btnSpellCheck != null && txtComments != null) btnSpellCheck.Attributes.Add("onclick", "javascript:WebSpellingCheck('" + this.WebSpellCheckerClientID + "','" + txtComments.ClientID + "')");
#endregion
ISessionManager sessionManger = ((BasePage)this.Page).sessionManger; if (sessionManger != null) { List<Response> responseList = sessionManger.Get(sessionId + "&" + QualitativeAssessmentSessionManager.RESPONSE_LIST) as List<Response>; if (responseList != null) { foreach (Response response in responseList.Where(resp => resp.questionId == questionId)) { if (showCommentsAlways.Equals("Y")) // Check if comments text box has to be shown always for this question { if (bShowCommentsBox == false) divComments.Attributes.Add("style", "display:block;"); bShowCommentsBox = true; displayType = "block"; } else { if (bShowCommentsBox == false) divComments.Attributes.Add("style", "display:none;"); bShowCommentsBox = true; displayType = "none"; } if (response.commentsRequired.Equals("Y")) { //divComments.Attributes.Add("style", "display:block;"); displayType = "block"; if ((response.answeredId != 0)) { divComments.Attributes.Add("style", "display:block;"); bShowCommentsBox = true; } }
if (txtComments != null && !String.IsNullOrEmpty(response.comments)) // If comments exist for this response, show the comments box { divComments.Attributes.Add("style", "display:block;"); bShowCommentsBox = true; displayType = "block"; txtComments.Text = response.comments; }
ListItem item = new ListItem();
item.Text = response.responseText; item.Value = response.responseId.ToString(); //item.Selected = (response.answeredId != 0);
if (checkedNA != null && checkedNA.ToUpper().ToString() == "TRUE") { string sOptNA = item.Text.Remove(0, 1);
if (sOptNA.ToUpper().Contains(") NOT APPLICABLE")) { item.Selected = true; txtComments.Text = Comments; divComments.Attributes.Add("style", "display:block;"); displayType = "block"; bShowCommentsBox = true; } else { bool NAPresent = false; foreach ( Response response1 in responseList.Where(resp => resp.questionId == questionId)) {
string sOptNACheck = response1.responseText.Remove(0, 1); if (sOptNACheck.ToUpper().Contains(") NOT APPLICABLE")) { NAPresent = true; } } if (NAPresent == false) { item.Selected = (response.answeredId != 0); } }
} else { item.Selected = (response.answeredId != 0); }
item.Attributes.Add("onclick", "javascript:ShowHideComment('" + divComments.ClientID + "','" + rfvComments.ClientID + "','" + response.commentsRequired.Equals("Y") + "','" + displayType + "','" + rblResponses.ClientID + "');"); rblResponses.Items.Add(item); } } }
#region "Set control as read only for Submitted/Approved status..." if (IsReadOnly) { HtmlGenericControl divCommentsReadOnly = ((HtmlGenericControl)e.Item.FindControl("divCommentsReadOnly")); if (divCommentsReadOnly != null) divCommentsReadOnly.Attributes.Add("style", "display:block;");
Literal ltrCommentsReadOnly = ((Literal)e.Item.FindControl("ltrCommentsReadOnly")); if (ltrCommentsReadOnly != null && txtComments != null && !string.IsNullOrEmpty(txtComments.Text)) ltrCommentsReadOnly.Text = "<u>Comments:</u><br />" + txtComments.Text; if (divComments != null) divComments.Attributes.Add("style", "display:none;"); if (rblResponses != null) rblResponses.Enabled = false; } #endregion } }
protected void ddlcomment_SelectedIndexChanged1(object sender, EventArgs e) {
try {
foreach (RepeaterItem item in repQuestionnaire.Items) { DropDownList ddlcomment = item.FindControl("ddlcomment") as DropDownList;
if (!String.IsNullOrEmpty(ddlcomment.SelectedValue)) { string comments = string.Empty; UserControl UC_txtComments = ((UserControl)item.FindControl("txtComments")); TextBox txtComments = ((TextBox)UC_txtComments.FindControl("txtMessage")); if (txtComments != null) txtComments.Text = hfddlcommentText.Value; if (hfddlcomment.Value != null || hfddlcomment.Value != "") { if(hfddlcomment.Value != "Select") ddlcomment.SelectedIndex = Convert.ToInt32(hfddlcomment.Value); // ddlcomment.SelectedItem.Text = hfddlcommentText.Value; } else { ddlcomment.SelectedIndex = 0; } //if (comments != "" && comments.Length > 4000) // throw new Exception("Error Comment-4000.$004: The length of comments is more than 4000. Please enter appropriate comment and try again"); //else if (comments != "" && comments.Length < 10) // throw new Exception("Error Comment-4000.$004: The length of comments is less than 10. Please enter appropriate comment and try again");
//int responseId = Convert.ToInt32(rblResponses.SelectedValue);
} } } catch (Exception ex) {
} }