As the title says: I was to be able to do a search bring the search data back into a gridview that has clickable rows and once a row is clicked i will need to grab some info from that row and place it in a new div location on the same page in order to add more information specifically for that row.
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" Runat="Server">
<div class="wrapperHistoricalData">
<fieldset style="margin-bottom:5px;margin-top:10px;border-color:#efefef;">
<legend>Search</legend>
<%-- <asp:UpdatePanel ID="uPanelTop" runat="server" >
<ContentTemplate>--%>
<div class="divFloatLeft">
<asp:TextBox ID="txtStudentFirstName" runat="server" placeholder="First Name or ID" ></asp:TextBox>
<asp:TextBox ID="txtStudentLastName" runat="server" placeholder="Last Name" ></asp:TextBox>
<asp:DropDownList ID="ddlClinicalType" runat="server" DataTextField="ClinicalTypeDesc" DataValueField="ClinicalTypeID" />
<asp:Button ID="btnSearch" runat="server" Text="Search" OnClick="btnSearch_Click" />
</div>
<asp:RequiredFieldValidator
ID="rfvClinicalType"
runat="server"
ControlToValidate="ddlClinicalType"
InitialValue=""
ErrorMessage="Please select a Clinical option!"
ForeColor="Red"
Style="margin-left: 25px;"/>
<%-- </ContentTemplate>
</asp:updatePanel>--%>
</fieldset>
</div>
<div class="wrapperHistoricalData">
<asp:updatePanel ID="uPanelData" runat="server" >
<ContentTemplate>
<asp:GridView ID="gvHistoricalData" runat="server" AutoGenerateColumns="false" AllowPaging="True" AllowSorting="True" CssClass="DataEntryGridView" RowStyle-CssClass="GvGrid" OnRowDataBound="gvHistoricalData_RowDataBound" OnRowCommand="gvHistoricalData_RowCommand">
<RowStyle CssClass="rowMain" />
<AlternatingRowStyle CssClass="rowAlt" />
<HeaderStyle CssClass="rowHeader" width="100px"/>
<Columns>
<asp:TemplateField HeaderText="Name" ItemStyle-HorizontalAlign="Center" >
<ItemStyle CssClass="noBorder"/>
<ItemTemplate>
<asp:Label runat="server" ID="lblName" Text='<%# Eval("FullName") %>' CssClass="StudentName" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
<EditRowStyle BackColor="#999999" />
<FooterStyle BackColor="#5D7B9D" ForeColor="White" Font-Bold="True" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" Font-Size="15px" />
<PagerStyle CssClass="UserMaintUsersPager" BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<SortedAscendingCellStyle BackColor="#E9E7E2" />
<SortedAscendingHeaderStyle BackColor="#506C8C" />
<SortedDescendingCellStyle BackColor="#FFFDF8" />
<SortedDescendingHeaderStyle BackColor="#6F8DAE" />
</asp:GridView>
</ContentTemplate>
</asp:updatePanel>
</div>
<div class="divInput" id="divtest">
<div> <--- this sint done being built yet but the information will be in here with more input boxes ---->
<asp:Label runat="server" ID="lbltest" Text="yeah"></asp:Label>
</div>
</div>
Currently when I click the row, it returns an error: "All the headers have been sent" I have left code in t=so you can see what i have tried and still cant get it to work,
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getClinicalTypes();
}
// Restore selected row color after postback
HighlightSelectedRow();
}
protected void Search(string fname, string lname, string clinicalType)
{
List<StudentInfo> studInfo = new List<StudentInfo>();
if((Regex.IsMatch(fname, @"\d")) )
{
studInfo = CTStudentSearch.ListSearch("I", fname, "", clinicalType);
}
else
{
studInfo = CTStudentSearch.ListSearch("N", fname, lname, clinicalType);
}
gvHistoricalData.DataSource = studInfo;
gvHistoricalData.DataBind();
}
protected void btnSearch_Click(object sender, EventArgs e)
{
string searchText = "";
string fname = (!string.IsNullOrWhiteSpace(txtStudentFirstName.Text)) ? txtStudentFirstName.Text : "";
string lname = (!string.IsNullOrWhiteSpace(txtStudentLastName.Text)) ? txtStudentLastName.Text : "";
bool clinicalTypeChecked = (ddlClinicalType.SelectedIndex > 0) ? true : false;
string clinicalType = null;
if (clinicalTypeChecked == true)
{
clinicalType = ddlClinicalType.SelectedValue;
Search(fname, lname, clinicalType);
}
}
protected void gvHistoricalData_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onMouseOver", "this.originalstyle=this.style.backgroundColor;this.style.backgroundColor='#5D7B9D';this.style.cursor='pointer';");
e.Row.Attributes.Add("OnMouseOut", "this.style.backgroundColor=this.originalstyle;");
// Updated script to prevent row selection if clicking inside an input, button, or link
//string script = "if(event.srcElement && (event.srcElement.tagName.toLowerCase() === 'input' || event.srcElement.tagName.toLowerCase() === 'button' || event.srcElement.tagName.toLowerCase() === 'a')) return;";
//e.Row.Attributes["onclick"] = script + Page.ClientScript.GetPostBackClientHyperlink(gvHistoricalData, "Select$" + e.Row.RowIndex);
// Add a hidden button inside the row to trigger postback
LinkButton lb = new LinkButton();
lb.CommandName = "Select";
lb.CommandArgument = e.Row.RowIndex.ToString();
lb.Style["display"] = "none"; // Hide the button
e.Row.Cells[0].Controls.Add(lb);
// Add OnClientClick event
lb.OnClientClick = "return showInputDiv(); ";
// Optionally, set a data attribute to store the row index
lb.Attributes["data-row-index"] = e.Row.RowIndex.ToString();
e.Row.Cells[0].Controls.Add(lb);
}
}

