Click here to Skip to main content
14,382,347 members
   

ASP.NET

 
GeneralRe: Retrieve Session Array variable to Array variable in Class Library Project Pin
Member 1115418813-Nov-19 3:48
memberMember 1115418813-Nov-19 3:48 
GeneralRe: Retrieve Session Array variable to Array variable in Class Library Project Pin
Richard Deeming13-Nov-19 4:36
mveRichard Deeming13-Nov-19 4:36 
GeneralRe: Retrieve Session Array variable to Array variable in Class Library Project Pin
Member 1115418813-Nov-19 5:58
memberMember 1115418813-Nov-19 5:58 
Questionwhat is major difference between blazor server app and asp.net mvc razor app? Pin
Nitin Sawant11-Nov-19 19:10
professionalNitin Sawant11-Nov-19 19:10 
AnswerRe: what is major difference between blazor server app and asp.net mvc razor app? Pin
Mycroft Holmes11-Nov-19 21:20
memberMycroft Holmes11-Nov-19 21:20 
GeneralRe: what is major difference between blazor server app and asp.net mvc razor app? Pin
Nitin Sawant11-Nov-19 23:04
professionalNitin Sawant11-Nov-19 23:04 
GeneralRe: what is major difference between blazor server app and asp.net mvc razor app? Pin
jkirkerx13-Nov-19 10:56
professionaljkirkerx13-Nov-19 10:56 
Questiongridview with dynamic dropdownlist control null exception Pin
Anand Solomon11-Nov-19 5:41
memberAnand Solomon11-Nov-19 5:41 
I have a GridView with template fields and one of the template field is a dropdownlist which is dynamically added into the gridview control. It's working properly on page load when I click the button control to the get the values from the template fields it will throw a null reference exception. Please correct my error, I am in pathetic situation. I attached the source code.

Regards

rites|Alert Moderators
asolmduasolmdu
None

0 Points

1 Post

gridview with dynamic dropdownlist control null exception
33 minutes ago|LINK|157.50.247.59

I have a GridView with template fields and one of the template field is a dropdownlist which is dynamically added into the gridview control. It's working properly on page load when I click the button control to the get the values from the template fields it will throw a null reference exception. Please correct my error, I am in pathetic situation. I attached the source code.

Regards

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false"
        OnRowCreated="GridView1_RowCreated">
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="id" runat="server" Text='<%# Eval("RGNO") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="name" runat="server" Text='<%# Eval("NAME") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:Label ID="lastname" runat="server" Text='<%# Eval("DOB") %>'></asp:Label>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <Columns>
            <asp:TemplateField>
                <ItemTemplate>
                    <asp:PlaceHolder ID="PlaceHolder1" runat="server"></asp:PlaceHolder>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
    </asp:GridView>


protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
            BindGridView();
    }

    protected void GridView1_RowCreated(object sender, GridViewRowEventArgs e)
    {
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            DropDownList ddlResult = new DropDownList();
            ddlResult.ID = "ddlResult";
            ddlResult.Items.Insert(0, new ListItem("PASS", "0"));
            ddlResult.Items.Insert(1, new ListItem("FAIL", "1"));

            PlaceHolder p = (PlaceHolder)e.Row.FindControl("PlaceHolder1");
            p.Controls.Add(ddlResult);
        }
    }

    private void BindGridView()
    {
        GridView1.DataSource = CreateDataSource();
        GridView1.DataBind();
    }

    public DataTable CreateDataSource()
    {
        DataTable dt = new DataTable();
        DataRow dr;

        dt.Columns.Add(new DataColumn("RGNO", typeof(string)));
        dt.Columns.Add(new DataColumn("NAME", typeof(string)));
        dt.Columns.Add(new DataColumn("DOB", typeof(string)));

        dr = dt.NewRow();
        dr["RGNO"] = "1001";
        dr["NAME"] = "PRAKASH";
        dr["DOB"] = "10-10-2003";
        dt.Rows.Add(dr);
        return dt;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        foreach (GridViewRow row in GridView1.Rows)
        {
            DropDownList dd1 = (DropDownList)row.FindControl("ddlResult");
            Response.Write(dd1.SelectedItem.Text);
        }
    }

Questionvideo calling in asp.net Pin
Member 146439065-Nov-19 19:37
memberMember 146439065-Nov-19 19:37 
AnswerRe: video calling in asp.net Pin
F-ES Sitecore6-Nov-19 2:04
mveF-ES Sitecore6-Nov-19 2:04 
AnswerRe: video calling in asp.net Pin
Blikkies6-Nov-19 2:28
professionalBlikkies6-Nov-19 2:28 
Questioni want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Member 134445211-Nov-19 21:17
memberMember 134445211-Nov-19 21:17 
AnswerRe: i want show page numbers in bottom of the page like <1 2 3 4 5.......10 11 12> but it shows <1 2 3 4 5 6 to total> Pin
Richard Deeming3-Nov-19 23:33
mveRichard Deeming3-Nov-19 23:33 
QuestionASP.Net Core Identity Pin
Mycroft Holmes28-Oct-19 14:11
memberMycroft Holmes28-Oct-19 14:11 
AnswerRe: ASP.Net Core Identity Pin
jkirkerx30-Oct-19 14:10
professionaljkirkerx30-Oct-19 14:10 
GeneralRe: ASP.Net Core Identity Pin
Mycroft Holmes31-Oct-19 12:13
memberMycroft Holmes31-Oct-19 12:13 
GeneralRe: ASP.Net Core Identity Pin
jkirkerx1-Nov-19 13:23
professionaljkirkerx1-Nov-19 13:23 
QuestionImporting Rows Into a List Pin
ibrahimayhans28-Oct-19 1:37
memberibrahimayhans28-Oct-19 1:37 
QuestionASP maker 2018 Pin
Member 1292025327-Oct-19 12:23
memberMember 1292025327-Oct-19 12:23 
AnswerRe: ASP maker 2018 Pin
Richard MacCutchan27-Oct-19 23:19
protectorRichard MacCutchan27-Oct-19 23:19 
QuestionDraw Shape in Canvas Pin
John_Ryder26-Oct-19 2:58
memberJohn_Ryder26-Oct-19 2:58 
AnswerRe: Draw Shape in Canvas Pin
Afzaal Ahmad Zeeshan26-Oct-19 10:19
mveAfzaal Ahmad Zeeshan26-Oct-19 10:19 
GeneralRe: Draw Shape in Canvas Pin
John_Ryder29-Oct-19 20:49
memberJohn_Ryder29-Oct-19 20:49 
AnswerRe: Draw Shape in Canvas Pin
jkirkerx28-Oct-19 13:53
professionaljkirkerx28-Oct-19 13:53 
QuestionHow do i make my detailsviewmodel work Pin
Stefaneus22-Oct-19 7:31
memberStefaneus22-Oct-19 7:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.