내 데이터베이스에서 userID
을 얻으 려하면 DetailsView
에 넣고 값을 가져 와서 레이블로 설정하십시오.C# DetailsView 값을 얻으십시오
Im이 문자열이 비어 있다는 오류가 발생합니다.
public void SendButton_Click(object sender, EventArgs e)
{
labelID.Text = DetailsView1.Rows[0].Cells[1].Text;
strVariable = labelID.Text;
System.Diagnostics.Debug.Write("variabelen: " + strVariable);
System.Guid g = new Guid(strVariable);
SqlDataSource1.InsertParameters[3].DefaultValue = g.ToString();
SqlDataSource1.Insert();
}
<asp:Label ID="labelID" Name="LabelID" runat="server"></asp:Label>
<asp:DetailsView ID="DetailsView1" runat="server" AutoGenerateRows="False"
DataSourceID="SqlDataSource2" Height="50px" Width="125px"
DefaultMode="Edit">
<Fields>
<asp:BoundField DataField="UserId" HeaderText="UserId"
SortExpression="UserId" />
</Fields>
</asp:DetailsView>
<asp:SqlDataSource ID="SqlDataSource2" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT UserId FROM aspnet_Users WHERE (UserName = 'bo')">
</asp:SqlDataSource>
참고 labelID.Text
가 클릭 버튼 이벤트와 Detailview
(그리드) 로딩이 사용자가 로그인 할 때입니다. 사용자 ID GET의로드 detailsview1
에서 사용자가 로그인 될 때입니다.
어떻게 해결할 수 있습니까?
로그인 한 사용자의 ID를 가져 오시겠습니까? 그렇다면'User.Identity.Name'을 시도하십시오. – jrummell