I have some code and it is unable to take the values entered from a dropdown list or textbox and output them to a SharePoint List. here is the code
try
{
SPWeb web = SPContext.Current.Web;
web.AllowUnsafeUpdates = true;
SPList List = web.Lists["FORM D List"];
SPListItem NewItem = List.Items.Add();
string title = "this is new";
NewItem["Title"] = title;
NewItem.Update();
// NewItem.Update();
foreach (GridViewRow row in FormDGrid.Rows)
// for (int count = 0; count < FormDGrid.Rows.Count; count++)
{
NewItem["State"] = ((Label)FormDGrid.FindControl("StateField")).Text;
NewItem["County"] = ((DropDownList)FormDGrid.FindControl("CountyField")).Text;
NewItem["City or Town"] = ((TextBox)FormDGrid.FindControl("CityField")).Text;
NewItem.Update();
List.Update();
}
thoughts? the assignment of Title column works directly but if I try to link to a control within the GridView it fails.
edit: here is the code on the aspcx
<asp:TemplateField HeaderText="State" HeaderStyle-Width="70">
<ItemTemplate>
<asp:Label CssClass="ms-input" Width="70"
ID="lblState" Text='<%# DataBinder.Eval(Container.DataItem, "state")%>' runat='server' />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="County">
<ItemTemplate>
<asp:DropDownList ID="lblCounty" runat="server" CssClass="ms-input" Width="150">
<asp:ListItem Value="01">--select County here--</asp:ListItem>
<asp:ListItem Value="02">Columbia</asp:ListItem>
<asp:ListItem Value="03">Charleston</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="City or Town" HeaderStyle-Width="270" SortExpression="lll">
<ItemTemplate>
<asp:TextBox CssClass="ms-input" TextMode="SingleLine" MaxLength="3700" Width="270"
ID="lblCity" Text='<%# DataBinder.Eval(Container.DataItem, "cityorTown") %>' runat='server' />
</ItemTemplate>
</asp:TemplateField>