[Solved] ASP.Net GridView row details not displaying in Bootstrap modal popup on LinkButton Click

Mehram
 
on Nov 17, 2021 10:43 AM
Sample_898962.zip
688 Views

Sir,

Model page is not loading data on linkbutton click inside gridview

Model page is load but blank

Display GridView row details in Bootstrap modal popup on LinkButton click using C# and VB.Net in ASP.Net

Protected Sub Display(sender As Object, e As EventArgs)
    Dim rowIndex As Integer = Convert.ToInt32(TryCast(TryCast(sender, LinkButton).NamingContainer, GridViewRow).RowIndex)
    Dim row As GridViewRow = gvEducationlDet.Rows(rowIndex)
    ClearDataMemberEducation()
    hfMemberEducationID.Value = TryCast(row.FindControl("lblMemberEduID"), Label).Text
    'lblmonth.Text = TryCast(row.FindControl("lblMonth_Name"), Label).Text
    'txtAmount.Text = TryCast(row.FindControl("lblAmount"), Label).Text
    'LoadMemberEducationDetail(hfMemberEducationID.Value)
    Dim ObjMemberEducation As New clsmemberEducationDetail
    ObjMemberEducation.MemberEduID = hfMemberEducationID.Value
    ObjMemberEducation.CompanyID = Session("CompanyID")
    If ObjMemberEducation.LoadMemberEducationDet = False Then
        lblMessage.Text = "<div class=""alert alert-error"">" & ObjMemberEducation.ErrMessage & "</div>"
        Exit Sub
    Else
        txtMemberEducationID.Text = TryCast(row.FindControl("lblMemberEduID"), Label).Text 'ObjMemberEducation.MemberEduID
        'Session("CompanyID") = ObjMemberEducation.CompanyID
        hfMemberID.Value = ObjMemberEducation.MemberID
        hfWifeID.Value = ObjMemberEducation.MemberWifeID
        hfChildID.Value = ObjMemberEducation.MemberChildId
        cboHighestQualification.SelectedValue = ObjMemberEducation.HighestQualificationID
        cboAreaOfSpecialization.SelectedValue = ObjMemberEducation.AreaofSpecializationID
        txtInstitue.Text = ObjMemberEducation.Institute
        txtDegreeTitle.Text = ObjMemberEducation.DegreeTitle
        txtDegreeCompleteInYear.Text = ObjMemberEducation.DegreeCompleteInYear
        txtTotMarks.Text = ObjMemberEducation.TotalMarks
        txtObtainMarks.Text = ObjMemberEducation.ObtainMarks
        txtPercentage.Text = ObjMemberEducation.Percentage
        txtDescription.Text = ObjMemberEducation.Description
    End If
 
    ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "none", "<script>$('#mymodal').modal('show');</script>", False)
 
    'ClientScript.RegisterStartupScript(Me.[GetType](), "Pop", "<script>$('#mymodal').modal('show');</script>", False)
End Sub

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
arjunv
 
on Nov 18, 2021 06:31 AM
Mehram says:
ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "none", "<script>$('#mymodal').modal('show');</script>", False)

 Hi mehram, 

 You are making mistake in above quoted Code.

For more details please Refer below Sample.

HTML

<div class="modal fade" id="myModal" role="dialog">
    <div class="modal-dialog">
        <!-- Modal content-->
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    &times;</button>
                <h4 class="modal-title">Student Fee Details</h4>
            </div>
            <div class="modal-body">
                <div class="">
                    <div class="form-group">
                        <asp:Label ID="lblstudent" runat="server" Text="Aadmission No: "></asp:Label>
                        <asp:Label ID="lblstudentid" runat="server" Text=""></asp:Label>
                    </div>
                    <div class="form-group">
                        <asp:Label ID="Label1" runat="server" Text="Month"></asp:Label>
                        <asp:Label ID="lblmonth" runat="server" Text=""></asp:Label>
                    </div>
                    <div class="form-group">
                        <asp:Label ID="lblAmount" runat="server" Text="Amount"></asp:Label>
                        <asp:TextBox ID="txtAmount" runat="server" TabIndex="3" MaxLength="75" CssClass="form-control"
                            placeholder="Enter Amount"></asp:TextBox>
                    </div>
                </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-info" data-dismiss="modal">
                    Close</button>
                <asp:Button ID="btnSave" runat="server" Text="Save" OnClick="btnSave_Click" CssClass="btn btn-info" />
            </div>
        </div>
    </div>
</div>
<asp:GridView ID="gvEducationlDet" runat="server" CssClass="table table-striped table-hover"
    DataKeyNames="student_Id" AutoGenerateColumns="false" GridLines="None">
    <Columns>
        <asp:TemplateField HeaderText="Admission No">
            <ItemTemplate>
                <asp:Label ID="lblstudent_Id" runat="server" Text='<%# Eval("student_Id") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Month">
            <ItemTemplate>
                <asp:Label ID="lblMonth_Name" runat="server" Text='<%# Eval("Month_Name") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Amount">
            <ItemTemplate>
                <asp:Label ID="lblAmount" runat="server" Text='<%# Eval("Amount") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="IsPaid">
            <ItemTemplate>
                <asp:Label ID="lblIsPaid" runat="server" Text='<%# Eval("IsPaid") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="date">
            <ItemTemplate>
                <asp:Label ID="lbldate" runat="server" Text='<%# Eval("date") %>'></asp:Label>
            </ItemTemplate>
        </asp:TemplateField>
        <asp:TemplateField HeaderText="Pay">
            <ItemTemplate>
                <asp:LinkButton ID="lnkBtnEdit" runat="server" Text="Edit" CssClass="btn btn-info"
                    OnClick="Display"></asp:LinkButton>
            </ItemTemplate>
        </asp:TemplateField>
    </Columns>
</asp:GridView>

Namespace

C#

using System.Data;

VB.Net

Imports System.Data

Code

C#

protected void Page_Load(object sender, EventArgs e)
{
    if (!IsPostBack)
    {
        DataTable dt = new DataTable();
        dt.Columns.AddRange(new DataColumn[] {
            new DataColumn("student_Id")
            ,new DataColumn("Month_Name")
            ,new DataColumn("Amount")
            ,new DataColumn("IsPaid")
            ,new DataColumn("date")
        });

        dt.Rows.Add(1, "Jan", 5200, "Yes", DateTime.Now.AddDays(-263));
        dt.Rows.Add(2, "Feb", 6500, "No", DateTime.Now.AddDays(-50));
        dt.Rows.Add(3, "Mar", 7500, "", "");
        dt.Rows.Add(4, "Apr", 6333, "No", DateTime.Now.AddDays(-63));
        dt.Rows.Add(5, "Jun", 15000, "Yes", DateTime.Now.AddDays(-93));
        gvEducationlDet.DataSource = dt;
        gvEducationlDet.DataBind();
    }
}

protected void Display(object sender, EventArgs e)
{
    int rowIndex = Convert.ToInt32(((sender as LinkButton).NamingContainer as GridViewRow).RowIndex);
    GridViewRow row = gvEducationlDet.Rows[rowIndex];
    lblstudentid.Text = (row.FindControl("lblstudent_Id") as Label).Text;
    lblmonth.Text = (row.FindControl("lblMonth_Name") as Label).Text; ;
    txtAmount.Text = (row.FindControl("lblAmount") as Label).Text;

    ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "modal", "<script>window.onload=function(){$('#myModal').modal('show');}</script>", false);
}

protected void btnSave_Click(object sender, EventArgs e)
{

}

VB.Net

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
    If Not IsPostBack Then
        Dim dt As DataTable = New DataTable()
        dt.Columns.AddRange(New DataColumn() {New DataColumn("student_Id"), New DataColumn("Month_Name"), New DataColumn("Amount"), New DataColumn("IsPaid"), New DataColumn("date")})
        dt.Rows.Add(1, "Jan", 5200, "Yes", DateTime.Now.AddDays(-263))
        dt.Rows.Add(2, "Feb", 6500, "No", DateTime.Now.AddDays(-50))
        dt.Rows.Add(3, "Mar", 7500, "", "")
        dt.Rows.Add(4, "Apr", 6333, "No", DateTime.Now.AddDays(-63))
        dt.Rows.Add(5, "Jun", 15000, "Yes", DateTime.Now.AddDays(-93))
        gvEducationlDet.DataSource = dt
        gvEducationlDet.DataBind()
    End If
End Sub

Protected Sub Display(ByVal sender As Object, ByVal e As EventArgs)
    Dim rowIndex As Integer = Convert.ToInt32((TryCast((TryCast(sender, LinkButton)).NamingContainer, GridViewRow)).RowIndex)
    Dim row As GridViewRow = gvEducationlDet.Rows(rowIndex)
    lblstudentid.Text = (TryCast(row.FindControl("lblstudent_Id"), Label)).Text
    lblmonth.Text = (TryCast(row.FindControl("lblMonth_Name"), Label)).Text
    txtAmount.Text = (TryCast(row.FindControl("lblAmount"), Label)).Text
    ScriptManager.RegisterClientScriptBlock(Me, Me.GetType(), "modal", "<script>window.onload=function(){$('#myModal').modal('show');}</script>", False)
End Sub

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As EventArgs)
End Sub

Screenshot