각 행에 GridView
및 편집 링크가 있습니다. 편집을 클릭하여 GridView
셀의 데이터를 채우고 GridView
행을 업데이트 할 수 있으며 데이터베이스의 해당 테이블도 업데이트됩니다.GridView에서 빈 셀을 무시하는 방법
나는 on_click이 각 행을 열 단위로 읽고 몇 가지 작업을 수행하는 저장 버튼이 있습니다.
GridView
의 모든 셀에 일부 데이터가 채워져 있으면 함수가 제대로 작동합니다. GridView
의 셀이 비어 있으면 오류가 발생합니다. 입력 문자열의 형식이 올바르지 않습니다.
내가 시도하는 코드는 다음과 같습니다
protected void SAVE_GRID_Click(object sender, EventArgs e)
{
foreach (GridViewRow row in GridView2.Rows)
{
string Loc = row.Cells[1].Text;
string strg = "SELECT Location_Type FROM Quantity WHERE Locations='" + Loc + "'";
SqlCommand com = new SqlCommand(strg, con);
con.Open();
SqlDataReader sdr = com.ExecuteReader();
while (sdr.Read())
{
Loctype.Text = sdr[0].ToString().Trim();
}
con.Close();
for (int i = 1; i < GridView2.Columns.Count; i++)
{
String header = GridView2.Columns[i].HeaderText;
string str = "SELECT Profile_Type FROM Profile_Tooltip WHERE Profile_Name='"+header+"'";
SqlCommand cmd = new SqlCommand(str,con);
con.Open();
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
profiletype.Text = dr[0].ToString().Trim();
}
con.Close();
if (!string.IsNullOrEmpty(row.Cells[i + 1].Text.Trim()))
{
int n = Convert.ToInt16(row.Cells[i + 1].Text);
//int n = int.Parse(row.Cells[i].Text);
for (int m = Asset_List.Items.Count - 1; m >= 0; m--)
{
Asset_List.Items.Remove(Asset_List.Items[m]);
}
for (int j = 1; j <= n; j++)
{
Asset_List.Items.Add(string.Concat(profiletype.Text, j));
}
for (int k = 0; k <= Asset_List.Items.Count - 1; k++)
{
com = new SqlCommand("INSERT INTO " + Label3.Text + " VALUES ('" + Loctype.Text + "','" + Loc + "','" + header + "','" + Asset_List.Items[k] + "')", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
}
}
}
SqlCommand comd = new SqlCommand("SELECT * FROM " + Label3.Text + "", con);
SqlDataAdapter da = new SqlDataAdapter(comd);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
나는 셀이 비어있는 경우 내가 빈 셀에 대한 조치를 수행하지 않고 다음 셀로 증가 할 비어 있는지 확인하고 싶습니다.
친절하게이 문제를 해결하는 데 도움이됩니다. 고맙습니다.
* 휴식 *을 제거하십시오. – adatapost
여전히 동일한 오류 –
내 질문에 오류가 언급 된 –