<asp:TemplateColumn>
<HeaderTemplate>
<DIV align="center">Hours</DIV>
</HeaderTemplate>
<ItemTemplate>
<DIV align="center"><%# Container.DataItem("Hrs") %></DIV>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="ddldgHours" runat="server">
<asp:ListItem Value="4.00">4.00</asp:ListItem>
<asp:ListItem Value="3.00">3.00</asp:ListItem>
<asp:ListItem Value="2.00">2.00</asp:ListItem>
<asp:ListItem Value="1.00">1.00</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
I click on the edit command in the datagrid and this control displays fine, however whenever I click on the update command I receive an error 'Object reference not set to an instance to an object'. Does anyone have any suggestions? I can provide more code if necessary. Thanks.Hi,
If u are using code-behind, then u have to define the dropdownlist inside ur code-behind before using it.
i would like you to post the exact error that u are having, with some code, to know which is generating the error,
best of luck.
THIS IS THE SPECIFIC ERROR:
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.
THIS IS MY CODE FROM THE METHOD WHERE THE ERROR OCCURS:
'Visual Aspect of Page
pnl1.Visible = False
pnl2.Visible = False
pnl3.Visible = True
pnl4.Visible = False'THE NEXT LINE CAUSES THE ERROR
transcript.UpdateCourse(dgTranscript.DataKeys(e.Item.ItemIndex), _
GenerateIdentity(), _
txtdgCourseId.Text, _
txtdgTitle.Text, _
ddldgGrade.SelectedValue, _
ddldgHours.SelectedValue)txtCourseID.Text = Nothing
txtCourseTitle.Text = Nothing
dgTranscript.EditItemIndex = -1DisplayTranscript()
To get the value of ddldgGrade, you have to do something like this in the Update event handler:
strGrade = ((DropDownList)e.Item.FindControl("ddldgGrade")).SelectedValue;
I think that this is the syntax. I don't have all my good code with me, since I'm at work. The idea is that first you have to use the FindControl method of the DataGridItem class. Then you have to cast it to the correct class, which I'm guessing is DropDownList. Then, if you put parentheses around that, you can access the whole thing as one expression, and you can get the SelectedValue from that.
You can do the same thing with the TextBox. I'm sure you can take it from here. If you need more help, drop a line.
hello, the problem as i see it is from the "ddldgGrade" what is that a dropdownlist ? if yes, u have to initialize a dropdownlist in ur server-side code !!!! and try to use
ddldgGRade.SelectedItem.Text instead !!!!
hope these help
Combining the above metods worked best for me. I created a dropdownlist in my code and set it equal to "e.Item.FindControl("ddldgGrade")". Thanks for the help.
0 comments:
Post a Comment