Click here to Skip to main content
15,072,134 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Problem in linkbutton in gridview

I want retrive anthor table from linkbutton inside gridview,But i am not satified with look LE_YN column linkbutton plus label l_no is showing in cell ,I want Use linkbutton le_yn and click it see anthor table letter_dept
Main gridview table is viewyn
SQL
CREATE TABLE [dbo].[viewyn]
[l_no] [varchar](50) ,
[nam_dep] [varchar](50) ,
[no_deo] [int] NULL,
[no_mon] [int] NULL,
[le_yn] [varchar](50) ,
[dd_yn] [varchar](50)


le_yn is used linkbuttons
Now anthor table
SQL
CREATE TABLE [dbo].[Letter_dept](
[Dep_nam] [varchar](50),
[l_no] [varchar](50),
[le_jap] [varchar](50),
[date] [varchar](50),
[amount_dd] [int] NULL,
[le_yn] [varchar](50)
)


ASP.NET Syntax (Toggle Plain Text)
ASP.NET
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
 
<asp:GridView ID="GridView1" runat="server" 
AutoGenerateColumns="False" AllowPaging="True" DataSourceID="SqlDataSource1" 
        onselectedindexchanged="GridView1_SelectedIndexChanged" >
           <Columns>
            <asp:BoundField DataField="l_no" HeaderText="l_no" 
                   SortExpression="l_no" />
 
 
 
 
               <asp:BoundField DataField="nam_dep" HeaderText="nam_dep" 
                   SortExpression="nam_dep" />
               <asp:BoundField DataField="no_deo" HeaderText="no_deo" 
                   SortExpression="no_deo" />
               <asp:BoundField DataField="no_mon" HeaderText="no_mon" 
                   SortExpression="no_mon" />
                   <asp:TemplateField HeaderText="le_yn">
                   <ItemTemplate>
                   <asp:Label runat="server" ID="letterno" Text='<%# Eval("le_yn") %>'  />
                   <asp:LinkButton  runat="server" ID ="l_no"  Text='<%# Eval("l_no") %>'  OnClick="l_no_Click"   />
                   </ItemTemplate>
                   </asp:TemplateField>             
 
 
 
 
 
 
 
               <asp:BoundField DataField="dd_yn" HeaderText="dd_yn" SortExpression="dd_yn" />
           </Columns>
           </asp:GridView>
<asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server"
    TargetControlID="btnShowModalPopup"
    PopupControlID="divPopUp"
    BackgroundCssClass="popUpStyle"
    PopupDragHandleControlID="panelDragHandle"
    DropShadow="true">   </asp:ModalPopupExtender>
<asp:Button runat="server" ID="btnShowModalPopup" style="display:none"/>
 
 
        <div class="popUpStyle"  id="divPopUp"  style="display:none;">
    <asp:Panel runat="Server" ID="panelDragHandle" CssClass="drag">
 
    </asp:Panel>
    <asp:Label runat="server" ID="lblText" Text="letter no: "></asp:Label>
    <asp:Label ID="lblCustValue" runat="server"></asp:Label>
    <asp:GridView ID="GridView2" runat="server">
    </asp:GridView>                         
    <asp:Button ID="btnClose" runat="server" Text="Close" />
   <br />
</div>       
    </ContentTemplate>
</asp:UpdatePanel>
 
   <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
        ConnectionString="<%$ ConnectionStrings:JAPITConnectionString %>" 
        SelectCommand="SELECT * FROM [viewyn]"></asp:SqlDataSource>

ASP.NET Syntax (Toggle Plain Text)
C#
protected void l_no_Click(object sender, EventArgs e)
    {
        // Fetch the customer id
        LinkButton lb = sender as LinkButton;
        string l_no = lb.Text;
        lblCustValue.Text = l_no;
        // Connection
        string constr = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["JAPITConnectionString"].ConnectionString;
        string sql = "SELECT * FROM Letter_dept WHERE l_no= @l_no";
        SqlConnection connection = new SqlConnection(constr);
        connection.Open();
        SqlCommand cmd = new SqlCommand(sql, connection);
        cmd.Parameters.AddWithValue("@l_no", l_no);
        cmd.CommandType = CommandType.Text;
 
        SqlDataReader dr = cmd.ExecuteReader();
        // Bind the reader to the GridView
        // You can also use a lighter control
        // like the Repeater to display data
        GridView2.DataSource = dr;
        GridView2.DataBind();
        connection.Close();
        // Show the modalpopupextender
        ModalPopupExtender1.Show();
 
    }
Posted
Updated 17-Dec-11 3:36am
v2

1 solution

If you are not satisfied with the look then use CSS to change it or use a Template column to add controls as you desire.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900