C
CJM
[code snippets at the end]
I have a page that allows the user to search a DB by querying one of 3
fields. When results are returned, I want the user to be able to click a
value in one of three columns (that directly relate to the 3 searchable
fields) and have the page postback and requery given the selected criterion.
For example, the user searches for retainer #1, which has a Tip Width of 5.
So he clicks on the 5 and it searches again for all retainers that have a
similar Tip Width.
To achieve this, I have a Gridview with several BoundFields and one
LinkButton (within a Template) for each of the 3 searcable columns. So far
so good...
I'm strugglin however to make the next move. I don't know how to code it so
that by clicking on a LinkButton, the SearchVal field is repopulated with
the selected value, the SearchType radio button is set to the appropriate
type, and the btnSearch_Click sub is called. I'm not sure which event of
which control I need to create a handler for, nor what I do thereafter.
I imagine this is quite simple, but it's my first proper ASP.NET
application, so I'm still rather out of my depth. I've searched for
examples, but I haven't found one that matches this scenario, though there
have been plenty of hints that this is a commonly used approach.
Can anyone point me in the rifght direction?
Thanks in advance.
CJM
Snippets:
<fieldset>
<legend>Search Criteria</legend>
<table id="search">
<tr>
<td>Search Value:</td>
<td><asp:TextBox ID="SearchVal" TextMode="SingleLine" MaxLength="20"
runat="server" Columns="20" /></td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoRetainer"
Text="Retainer No:" Checked runat="server" /></td>
</tr>
<tr>
<td colspan="2"> </td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoTipWidth"
Text="Tip Width:" runat="server" /></td>
</tr>
<tr>
<td> </td>
<td><asp:Button ID="btnSearch" Text="Search" runat="server" /></td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoFlange"
Text="Ideal Flange" runat="server" /></td>
</tr>
</table>
<asp:Label ID="lblFeedback" Text="feedback" runat="server"/>
</fieldset>
<asp:GridView ID="grdRetainers" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:TemplateField HeaderText="Retainer">
<ItemTemplate>
<asp:LinkButton CommandName="ViewRetainer" ID="btnRetainer"
runat="server"><%#Eval("RetNo")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tip Width">
<ItemTemplate>
<asp:LinkButton CommandName="SearchByTipWidth" ID="btnTipWidth"
runat="server"><%#Eval("TipWidth")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Thick" DataField="Thickness" />
<asp:BoundField HeaderText="Depth" DataField="Depth" />
<asp:BoundField HeaderText="Style" DataField="Style" />
<asp:BoundField HeaderText="Angle" DataField="InternalAngle" />
<asp:BoundField HeaderText="Dev Width" DataField="DevelopedWidth" />
<asp:TemplateField HeaderText="Flange">
<ItemTemplate>
<asp:LinkButton o OnCommand="" CommandName="SearchByFlange"
ID="btnFlange" runat="server"><%#Eval("IdealFlangeTip")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
Dim oConn As New SqlConnection("..etc...")
Dim oCmd As New SqlCommand
Dim drRetainers As SqlDataReader
oConn.Open()
With oCmd
.Connection = oConn
.CommandType = Data.CommandType.StoredProcedure
.Parameters.Clear()
If rdoRetainer.Checked Then
.CommandText = "mnd_ListRetainersByRetNo"
.Parameters.Add("RetainerNo", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
If rdoTipWidth.Checked Then
'lblFeedback.Text = lblFeedback.Text & " 1"
.CommandText = "mnd_ListRetainersByTipWidth"
.Parameters.Add("TipWidth", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
If rdoFlange.Checked Then
.CommandText = "mnd_ListRetainersByFlange"
.Parameters.Add("Flange", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
End With
drRetainers = oCmd.ExecuteReader
With grdRetainers
'lblFeedback.Text = lblFeedback.Text & " 2"
.DataSource = drRetainers
.DataBind()
.GridLines = GridLines.None
.CellSpacing = 1
End With
oConn.Close()
drRetainers.Close()
I have a page that allows the user to search a DB by querying one of 3
fields. When results are returned, I want the user to be able to click a
value in one of three columns (that directly relate to the 3 searchable
fields) and have the page postback and requery given the selected criterion.
For example, the user searches for retainer #1, which has a Tip Width of 5.
So he clicks on the 5 and it searches again for all retainers that have a
similar Tip Width.
To achieve this, I have a Gridview with several BoundFields and one
LinkButton (within a Template) for each of the 3 searcable columns. So far
so good...
I'm strugglin however to make the next move. I don't know how to code it so
that by clicking on a LinkButton, the SearchVal field is repopulated with
the selected value, the SearchType radio button is set to the appropriate
type, and the btnSearch_Click sub is called. I'm not sure which event of
which control I need to create a handler for, nor what I do thereafter.
I imagine this is quite simple, but it's my first proper ASP.NET
application, so I'm still rather out of my depth. I've searched for
examples, but I haven't found one that matches this scenario, though there
have been plenty of hints that this is a commonly used approach.
Can anyone point me in the rifght direction?
Thanks in advance.
CJM
Snippets:
<fieldset>
<legend>Search Criteria</legend>
<table id="search">
<tr>
<td>Search Value:</td>
<td><asp:TextBox ID="SearchVal" TextMode="SingleLine" MaxLength="20"
runat="server" Columns="20" /></td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoRetainer"
Text="Retainer No:" Checked runat="server" /></td>
</tr>
<tr>
<td colspan="2"> </td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoTipWidth"
Text="Tip Width:" runat="server" /></td>
</tr>
<tr>
<td> </td>
<td><asp:Button ID="btnSearch" Text="Search" runat="server" /></td>
<td><asp:RadioButton GroupName="SearchField" ID="rdoFlange"
Text="Ideal Flange" runat="server" /></td>
</tr>
</table>
<asp:Label ID="lblFeedback" Text="feedback" runat="server"/>
</fieldset>
<asp:GridView ID="grdRetainers" AutoGenerateColumns="False" runat="server">
<Columns>
<asp:TemplateField HeaderText="Retainer">
<ItemTemplate>
<asp:LinkButton CommandName="ViewRetainer" ID="btnRetainer"
runat="server"><%#Eval("RetNo")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Tip Width">
<ItemTemplate>
<asp:LinkButton CommandName="SearchByTipWidth" ID="btnTipWidth"
runat="server"><%#Eval("TipWidth")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Thick" DataField="Thickness" />
<asp:BoundField HeaderText="Depth" DataField="Depth" />
<asp:BoundField HeaderText="Style" DataField="Style" />
<asp:BoundField HeaderText="Angle" DataField="InternalAngle" />
<asp:BoundField HeaderText="Dev Width" DataField="DevelopedWidth" />
<asp:TemplateField HeaderText="Flange">
<ItemTemplate>
<asp:LinkButton o OnCommand="" CommandName="SearchByFlange"
ID="btnFlange" runat="server"><%#Eval("IdealFlangeTip")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
Protected Sub btnSearch_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnSearch.Click
Dim oConn As New SqlConnection("..etc...")
Dim oCmd As New SqlCommand
Dim drRetainers As SqlDataReader
oConn.Open()
With oCmd
.Connection = oConn
.CommandType = Data.CommandType.StoredProcedure
.Parameters.Clear()
If rdoRetainer.Checked Then
.CommandText = "mnd_ListRetainersByRetNo"
.Parameters.Add("RetainerNo", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
If rdoTipWidth.Checked Then
'lblFeedback.Text = lblFeedback.Text & " 1"
.CommandText = "mnd_ListRetainersByTipWidth"
.Parameters.Add("TipWidth", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
If rdoFlange.Checked Then
.CommandText = "mnd_ListRetainersByFlange"
.Parameters.Add("Flange", Data.SqlDbType.VarChar, 10).Value =
SearchVal.Text
End If
End With
drRetainers = oCmd.ExecuteReader
With grdRetainers
'lblFeedback.Text = lblFeedback.Text & " 2"
.DataSource = drRetainers
.DataBind()
.GridLines = GridLines.None
.CellSpacing = 1
End With
oConn.Close()
drRetainers.Close()