Hi,
My requirement is, if i click on Manage button of gridview then it should show all the data in the textbox from database.
I
have problem, It is working fine If contactusID visible="true" and when
it is false then if i select row on gridview first time,its fine and if
i select any row second time, i am getting error. There is no row at
position 4 and my counter starts with 0, and i have 4 rows in my grid.
Code:-
protected void gvAppContactUs_SelectedIndexChanged(object sender, EventArgs e)
{
mvDefault.SetActiveView(vModifyApp);
VModifyContactUsInView();
hfIsNewContact.Value = false.ToString();
NewContact(false);
StyleUtility.EnableButton(btnDelete);
}
protected void VModifyContactUsInView()
{
lblApplicationName.Text = hfSysName.Value;
tcContactUs.ActiveTabIndex = 0;
LinkApplicationSearch.Visible = true;
LtrManageApplicationContactUs.Visible = false;
LtrManageApplicationRoles.Visible = false;
LtrRoleDetails.Visible = false;
LtrSeparator0.Visible = false;
LtrSeparator1.Visible = true;
LtrSeparator2.Visible = true;
LinkManageApplicationContactUs.Visible = true;
LinkManageApplicationContactUs.Text = gvApplications.SelectedDataKey["DisplayName"].ToString();
LtrContactUsDetails.Visible = true;
LtrContactUsDetails.Text = lblApplicationName.Text;
ltrContactUsDetailsContactUsName.Visible = true;
ltrContactUsDetailsContactUsName.Text = lblApplicationName.Text;
btnContactUsDelete.Enabled = false;
mvDefault.SetActiveView(vModifyContactUs);
ApplicationContactUsDal dalContact = new ApplicationContactUsDal();
DataTable dtContact = dalContact.GetAllContactUsInfo(hfSysName.Value);
String selectedContactUsID = gvAppContactUs.SelectedRow.Cells[0].Text;
int selectedRowId;
for (selectedRowId = 0; selectedRowId <dtContact.Rows.Count; selectedRowId++)
{
if ((dtContact.Rows[selectedRowId]["ContactUsID"].ToString()).Equals(selectedContactUsID))
{
Session["contactUsID"] = selectedContactUsID;
break;
}
}
hfContactUsID.Value = selectedContactUsID;
hfApplicationName.Value = dtContact.Rows[selectedRowId]["ApplicationName"].ToString();
txtOpenDaysOfWeek.Text = dtContact.Rows[selectedRowId]["OpenDaysOfWeek"].ToString();
txtTimings.Text = dtContact.Rows[selectedRowId]["Timings"].ToString();
txtTimeZone.Text = dtContact.Rows[selectedRowId]["TimeZone"].ToString();
txtPhoneNumber.Text = dtContact.Rows[selectedRowId]["PhoneNumber"].ToString();
txtPhoneNumber2.Text = dtContact.Rows[selectedRowId]["PhoneNumber2"].ToString();
txtPhoneExtension.Text = dtContact.Rows[selectedRowId]["PhoneExtension"].ToString();
txtEmailAddress.Text = dtContact.Rows[selectedRowId]["EmailAddress"].ToString();
LinkManageApplicationContactUs.Text = gvAppContactUs.SelectedDataKey["ApplicationName"].ToString();
tcPanelContactUsDetails.Visible = true;
btnContactUsDelete.Enabled = false;
gvAppContactUs.SelectedIndex = -1;
lblApplicationName.Visible = true;
BindAppContactUsGV();
BindRoleWorkflow();
SetBreadCrumbs();
}
protected void BindAppContactUsGV()
{
// Get a list of Application ContactUs information
List<ContactUs> appContactUsInfo = new List<ContactUs>(ContactUs.FindAllContactUsInfo(hfSysName.Value));
// Sort Selected Roles
switch (this.gvAppContactUs_sortOrder)
{
case "ContactUsID":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.ContactUsID).ToList();
break;
case "ApplicationName":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.ApplicationName).ToList();
break;
case "OpenDaysOfWeek":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.OpenDaysOfWeek).ToList();
break;
case "Timings":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.Timings).ToList();
break;
case "TimeZone":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.TimeZone).ToList();
break;
case "PhoneNumber2":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.PhoneNumber2).ToList();
break;
case "PhoneNumber":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.PhoneNumber).ToList();
break;
case "PhoneExtension":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.PhoneExtension).ToList();
break;
case "EmailAddress":
appContactUsInfo = appContactUsInfo.OrderBy(item => item.EmailAddress).ToList();
break;
}
if (this.gvAppContactUs_sortReverse)
{
appContactUsInfo.Reverse();
}
gvAppContactUs.DataSource = appContactUsInfo.ToArray();
gvAppContactUs.DataBind();
// String selectedContactUsID = gvAppContactUs.SelectedRow.Cells[0].Text;
gvAppContactUs.Columns[0].Visible = false;
//tpAppContactUsInfo.TabIndex = 7;
//Tabs.ActiveTab = vModifyApp.Controls[7];
//Tabs.ActiveTabIndex = 7;
//FreezeForContactUs(true);
}
aspx code: -
<ajaxToolkit:TabPanel ID="tpAppContactUsInfo" runat="server" HeaderText="Application Contact Information" TabIndex="7">
<ContentTemplate>
<div>
<asp:Panel ID="pnlAppContactGV"
runat="server" Font-Names="Arial" Font-Size="10pt"
GroupingText="Application Contacts">
<div id="SearchAppContactUsResultsData" runat="server" style="text-align: right; font-size: small;
background-color: #F0F0F0; border-top: solid 1px #C0C0C0; padding-right: 2px">
<asp:Label ID="AppContactUsResultDetails" runat="server" />
<asp:GridView ID="gvAppContactUs" runat="server" AllowPaging="true"
AllowSorting="true" AutoGenerateColumns="False" BorderStyle="None"
CellPadding="4" CssClass="gridView" DataKeyNames="ApplicationName"
EmptyDataText="There are no Contact information to display." ForeColor="#333333"
GridLines="None" OnPageIndexChanging="gvAppContactUs_PageIndexChanging"
OnSelectedIndexChanged="gvAppContactUs_SelectedIndexChanged"
OnSorting="gvAppContactUs_Sorting" PageSize="15" Width="100%">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns >
<asp:BoundField
DataField="ContactUsID" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left"
HeaderText="ContactUSID" SortExpression="ContactUsID" Visible="true"/>
<asp:BoundField
DataField="ApplicationName" HeaderStyle-HorizontalAlign="Left"
ItemStyle-HorizontalAlign="Left"
HeaderText="Application Name" SortExpression="ApplicationName" />
<asp:BoundField DataField="OpenDaysOfWeek" HeaderStyle-HorizontalAlign="Left"
HeaderText="Support Days" SortExpression="OpenDaysOfWeek" />
<asp:BoundField DataField="Timings" HeaderStyle-HorizontalAlign="Left"
HeaderText="Support Time" SortExpression="Timings" />
<asp:BoundField DataField="TimeZone" HeaderStyle-HorizontalAlign="Left"
HeaderText="TimeZone" SortExpression="TimeZone" />
<asp:BoundField DataField="PhoneNumber" HeaderStyle-HorizontalAlign="Left"
HeaderText="PhoneNo" SortExpression="PhoneNumber" />
<asp:BoundField DataField="PhoneNumber2" HeaderStyle-HorizontalAlign="Left"
HeaderText="PhoneNo2" SortExpression="PhoneNumber2" />
<asp:BoundField DataField="PhoneExtension" HeaderStyle-HorizontalAlign="Left"
HeaderText="PhoneExt" SortExpression="PhoneExtension" />
<asp:BoundField DataField="EmailAddress" HeaderStyle-HorizontalAlign="Left"
HeaderText="EmailAddress" SortExpression="EmailAddress" />
<asp:CommandField ButtonType="Button" ControlStyle-CssClass="btn"
ItemStyle-HorizontalAlign="Right" SelectText="Manage"
ShowSelectButton="True" />
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="Gold" Font-Bold="True" ForeColor="Black" />
<PagerStyle BackColor="#414E6E"
BorderStyle="None" BorderWidth="0px" Font-Names="Arial"
ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle CssClass="gridViewHeader"
Font-Bold="True" Font-Names="Arial" ForeColor="Black" />
<AlternatingRowStyle BackColor="#EEEEFF" ForeColor="Black" />
</asp:GridView>
</div><br />
<asp:Button ID="btnNewContactUs" runat="server" CssClass="btn"
OnClick="btnNewContactUs_Click" Text="New ContactUs" UseSubmitBehavior="false"
Width="100px" />
</asp:Panel>
</div>
</ContentTemplate>
</ajaxToolkit:TabPanel>