我正在尝试在我的网站上为我的用户创建一个个人资料页面,他们可以在这里编辑个人资料。我已经使用了这个代码,但它无法正常工作
ASPX页面
欢迎
,
<br />
Full Name
<asp:TextBox ID="TextBox1" runat="server" style="width:250px; height:25px; border:thin solid #0099FF"></asp:TextBox>
<br />
<br />
Company Name
<asp:TextBox ID="TextBox2" runat="server" style="width:250px; height:25px; border:thin solid #0099FF"></asp:TextBox>
<br />
<br />
网络链接
<br />
<br />
E Mail
<asp:TextBox ID="TextBox4" runat="server" style="width:250px; height:25px; border:thin solid #0099FF"></asp:TextBox>
<br />
<br />
联系电话
地点
Upload Logo
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<br />
Company Info <br />
业务类型
<br />
<br />
Listings Remaining
<asp:Label ID="Label2" runat="server" Text=""></asp:Label>
<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" Text="Update" CssClass="button"
Width="115px" onclick="Button1_Click" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString1 %>"
SelectCommand="SELECT fname, cmpny, weblnk, email, cntct, lctn, cdscrptn, bsnstp FROM orgs WHERE (cmpny = @cmpny)"
UpdateCommand="Update [orgs] Set [fname]=@fname,[weblnk]=@weblnk,[email]=@email,[cntct]=@cntct,[lctn]=@lctn,[cdscrptn]=@cdscrptn,[bsnstp]=@bsnstp WHERE [cmpny]=@cmpny">
<SelectParameters>
<asp:QueryStringParameter Name="cmpny" Type="String" QueryStringField="cmpny" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="fname" Type="String" />
<asp:Parameter Name="weblnk" Type="String" />
<asp:Parameter Name="email" Type="String" />
<asp:Parameter Name="cntct" Type="String" />
<asp:Parameter Name="lctn" Type="String" />
<asp:Parameter Name="cdscrptn" Type="String" />
<asp:Parameter Name="bsnstp" Type="String" />
<asp:Parameter Name="cmpny" />
</UpdateParameters>
ASPX.CS页面
if (!Page.IsPostBack)
{
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataRowView row = dv[0];
TextBox1.Text = row["fname"].ToString();
TextBox2.Text = row["cmpny"].ToString();
TextBox3.Text = row["weblnk"].ToString();
TextBox4.Text = row["email"].ToString();
TextBox5.Text = row["cntct"].ToString();
TextBox6.Text = row["lctn"].ToString();
TextBox7.Text = row["cdscrptn"].ToString();
TextBox8.Text = row["bsnstp"].ToString();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
DataRowView row = dv[0];
SqlDataSource1.UpdateParameters["fname"].DefaultValue = TextBox1.Text.ToString();
SqlDataSource1.UpdateParameters["cmpny"].DefaultValue = TextBox2.Text.ToString();
SqlDataSource1.UpdateParameters["weblnk"].DefaultValue = TextBox3.Text.ToString();
SqlDataSource1.UpdateParameters["email"].DefaultValue = TextBox4.Text.ToString();
SqlDataSource1.UpdateParameters["cntct"].DefaultValue = TextBox5.Text.ToString();
SqlDataSource1.UpdateParameters["lctn"].DefaultValue = TextBox6.Text.ToString();
SqlDataSource1.UpdateParameters["cdscrptn"].DefaultValue = TextBox7.Text.ToString();
SqlDataSource1.UpdateParameters["bsnstp"].DefaultValue = TextBox8.Text.ToString();
//requisition_id = @requisition_id
SqlDataSource1.UpdateParameters["cmpny"].DefaultValue = row["cmpny"].ToString();
SqlDataSource1.Update();
}
我收到System.NullReferenceException:对象引用未设置为对象的实例。